{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}
module Text.Pandoc.Readers.Markdown (
readMarkdown,
yamlToMeta,
yamlToRefs ) where
import Control.Monad
import Control.Monad.Except (throwError)
import Data.Bifunctor (second)
import Data.Char (isAlphaNum, isPunctuation, isSpace)
import Data.List (transpose, elemIndex, sortOn, foldl')
import qualified Data.Map as M
import Data.Maybe
import qualified Data.Set as Set
import qualified Data.Attoparsec.Text as A
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.ByteString as BS
import System.FilePath (addExtension, takeExtension, takeDirectory)
import qualified System.FilePath.Windows as Windows
import qualified System.FilePath.Posix as Posix
import Text.DocLayout (realLength)
import Text.HTML.TagSoup hiding (Row)
import Text.Pandoc.Builder (Blocks, Inlines)
import qualified Text.Pandoc.Builder as B
import Text.Pandoc.Class.PandocMonad (PandocMonad (..), report)
import Text.Pandoc.Definition as Pandoc
import Text.Pandoc.Emoji (emojiToInline)
import Text.Pandoc.Error
import Safe.Foldable (maximumBounded)
import Text.Pandoc.Logging
import Text.Pandoc.Options
import Text.Pandoc.Walk (walk)
import Text.Pandoc.Parsing hiding (tableCaption)
import Text.Pandoc.Readers.HTML (htmlInBalanced, htmlTag, isBlockTag,
isCommentTag, isInlineTag, isTextTag)
import Text.Pandoc.Readers.LaTeX (applyMacros, rawLaTeXBlock, rawLaTeXInline)
import Text.Pandoc.Shared
import Text.Pandoc.URI (escapeURI, isURI, pBase64DataURI)
import Text.Pandoc.XML (fromEntities)
import Text.Pandoc.Readers.Metadata (yamlBsToMeta, yamlBsToRefs, yamlMetaBlock)
type MarkdownParser m = ParsecT Sources ParserState m
type F = Future ParserState
readMarkdown :: (PandocMonad m, ToSources a)
=> ReaderOptions
-> a
-> m Pandoc
readMarkdown :: forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> a -> m Pandoc
readMarkdown ReaderOptions
opts a
s = do
parsed <- ParsecT Sources ParserState m Pandoc
-> ParserState -> Sources -> m (Either PandocError Pandoc)
forall (m :: * -> *) t st a.
(Monad m, ToSources t) =>
ParsecT Sources st m a -> st -> t -> m (Either PandocError a)
readWithM ParsecT Sources ParserState m Pandoc
forall (m :: * -> *). PandocMonad m => MarkdownParser m Pandoc
parseMarkdown ParserState
forall a. Default a => a
def{ stateOptions = opts }
(Int -> Sources -> Sources
ensureFinalNewlines Int
3 (a -> Sources
forall a. ToSources a => a -> Sources
toSources a
s))
case parsed of
Right Pandoc
result -> Pandoc -> m Pandoc
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Pandoc
result
Left PandocError
e -> PandocError -> m Pandoc
forall a. PandocError -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError PandocError
e
yamlToMeta :: PandocMonad m
=> ReaderOptions
-> Maybe FilePath
-> BS.ByteString
-> m Meta
yamlToMeta :: forall (m :: * -> *).
PandocMonad m =>
ReaderOptions -> Maybe FilePath -> ByteString -> m Meta
yamlToMeta ReaderOptions
opts Maybe FilePath
mbfp ByteString
bstr = do
let parser :: ParsecT Sources ParserState m Meta
parser = do
oldPos <- ParsecT Sources ParserState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
setPosition $ initialPos (fromMaybe "" mbfp)
meta <- yamlBsToMeta (fmap B.toMetaValue <$> parseBlocks) bstr
checkNotes
setPosition oldPos
st <- getState
let result = Future ParserState Meta -> ParserState -> Meta
forall s a. Future s a -> s -> a
runF Future ParserState Meta
meta ParserState
st
reportLogMessages
return result
parsed <- ParsecT Sources ParserState m Meta
-> ParserState -> Text -> m (Either PandocError Meta)
forall (m :: * -> *) t st a.
(Monad m, ToSources t) =>
ParsecT Sources st m a -> st -> t -> m (Either PandocError a)
readWithM ParsecT Sources ParserState m Meta
parser ParserState
forall a. Default a => a
def{ stateOptions = opts } (Text
"" :: Text)
case parsed of
Right Meta
result -> Meta -> m Meta
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Meta
result
Left PandocError
e -> PandocError -> m Meta
forall a. PandocError -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError PandocError
e
yamlToRefs :: PandocMonad m
=> (Text -> Bool)
-> ReaderOptions
-> Maybe FilePath
-> BS.ByteString
-> m [MetaValue]
yamlToRefs :: forall (m :: * -> *).
PandocMonad m =>
(Text -> Bool)
-> ReaderOptions -> Maybe FilePath -> ByteString -> m [MetaValue]
yamlToRefs Text -> Bool
idpred ReaderOptions
opts Maybe FilePath
mbfp ByteString
bstr = do
let parser :: ParsecT Sources ParserState m [MetaValue]
parser = do
case Maybe FilePath
mbfp of
Maybe FilePath
Nothing -> () -> ParsecT Sources ParserState m ()
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just FilePath
fp -> SourcePos -> ParsecT Sources ParserState m ()
forall (m :: * -> *) s u. Monad m => SourcePos -> ParsecT s u m ()
setPosition (SourcePos -> ParsecT Sources ParserState m ())
-> SourcePos -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ FilePath -> SourcePos
initialPos FilePath
fp
refs <- ParsecT Sources ParserState m (Future ParserState MetaValue)
-> (Text -> Bool)
-> ByteString
-> ParsecT Sources ParserState m (Future ParserState [MetaValue])
forall (m :: * -> *) st.
(PandocMonad m, HasLastStrPosition st) =>
ParsecT Sources st m (Future st MetaValue)
-> (Text -> Bool)
-> ByteString
-> ParsecT Sources st m (Future st [MetaValue])
yamlBsToRefs ((Blocks -> MetaValue)
-> Future ParserState Blocks -> Future ParserState MetaValue
forall a b.
(a -> b) -> Future ParserState a -> Future ParserState b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Blocks -> MetaValue
forall a. ToMetaValue a => a -> MetaValue
B.toMetaValue (Future ParserState Blocks -> Future ParserState MetaValue)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState MetaValue)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
parseBlocks) Text -> Bool
idpred ByteString
bstr
checkNotes
st <- getState
let result = Future ParserState [MetaValue] -> ParserState -> [MetaValue]
forall s a. Future s a -> s -> a
runF Future ParserState [MetaValue]
refs ParserState
st
reportLogMessages
return result
parsed <- ParsecT Sources ParserState m [MetaValue]
-> ParserState -> Text -> m (Either PandocError [MetaValue])
forall (m :: * -> *) t st a.
(Monad m, ToSources t) =>
ParsecT Sources st m a -> st -> t -> m (Either PandocError a)
readWithM ParsecT Sources ParserState m [MetaValue]
parser ParserState
forall a. Default a => a
def{ stateOptions = opts } (Text
"" :: Text)
case parsed of
Right [MetaValue]
result -> [MetaValue] -> m [MetaValue]
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return [MetaValue]
result
Left PandocError
e -> PandocError -> m [MetaValue]
forall a. PandocError -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError PandocError
e
isBulletListMarker :: Char -> Bool
isBulletListMarker :: Char -> Bool
isBulletListMarker Char
'*' = Bool
True
isBulletListMarker Char
'+' = Bool
True
isBulletListMarker Char
'-' = Bool
True
isBulletListMarker Char
_ = Bool
False
isHruleChar :: Char -> Bool
isHruleChar :: Char -> Bool
isHruleChar Char
'*' = Bool
True
isHruleChar Char
'-' = Bool
True
isHruleChar Char
'_' = Bool
True
isHruleChar Char
_ = Bool
False
setextHChars :: [Char]
setextHChars :: FilePath
setextHChars = FilePath
"=-"
inList :: PandocMonad m => MarkdownParser m ()
inList :: forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
inList = do
ctx <- ParserState -> ParserContext
stateParserContext (ParserState -> ParserContext)
-> ParsecT Sources ParserState m ParserState
-> ParsecT Sources ParserState m ParserContext
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
guard (ctx == ListItemState)
spnl :: PandocMonad m => ParsecT Sources st m ()
spnl :: forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m ()
spnl = ParsecT Sources st m () -> ParsecT Sources st m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources st m () -> ParsecT Sources st m ())
-> ParsecT Sources st m () -> ParsecT Sources st m ()
forall a b. (a -> b) -> a -> b
$ do
ParsecT Sources st m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
ParsecT Sources st m Char -> ParsecT Sources st m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Sources st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
ParsecT Sources st m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
ParsecT Sources st m Char -> ParsecT Sources st m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Char -> ParsecT Sources st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\n')
spnl' :: PandocMonad m => ParsecT Sources st m Text
spnl' :: forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m Text
spnl' = ParsecT Sources st m Text -> ParsecT Sources st m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources st m Text -> ParsecT Sources st m Text)
-> ParsecT Sources st m Text -> ParsecT Sources st m Text
forall a b. (a -> b) -> a -> b
$ do
xs <- ParsecT Sources st m Char -> ParsecT Sources st m FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Sources st m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
ys <- option "" $ try $ (:) <$> newline
<*> (many spaceChar <* notFollowedBy (char '\n'))
return $ T.pack $ xs ++ ys
indentSpaces :: PandocMonad m => MarkdownParser m Text
indentSpaces :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
indentSpaces = ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ do
tabStop <- (ReaderOptions -> Int) -> ParsecT Sources ParserState m Int
forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParsecT s st m b
forall s (m :: * -> *) t b.
Stream s m t =>
(ReaderOptions -> b) -> ParsecT s ParserState m b
getOption ReaderOptions -> Int
readerTabStop
countChar tabStop (char ' ') <|>
textStr "\t" <?> "indentation"
nonindentSpaces :: PandocMonad m => MarkdownParser m Text
nonindentSpaces :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
nonindentSpaces = do
n <- MarkdownParser m Int
forall (m :: * -> *). PandocMonad m => MarkdownParser m Int
skipNonindentSpaces
return $ T.replicate n " "
skipNonindentSpaces :: PandocMonad m => MarkdownParser m Int
skipNonindentSpaces :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Int
skipNonindentSpaces = do
tabStop <- (ReaderOptions -> Int) -> ParsecT Sources ParserState m Int
forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParsecT s st m b
forall s (m :: * -> *) t b.
Stream s m t =>
(ReaderOptions -> b) -> ParsecT s ParserState m b
getOption ReaderOptions -> Int
readerTabStop
gobbleAtMostSpaces (tabStop - 1) <* notFollowedBy spaceChar
litChar :: PandocMonad m => MarkdownParser m Text
litChar :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
litChar = Char -> Text
T.singleton (Char -> Text)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Char
forall (m :: * -> *). PandocMonad m => MarkdownParser m Char
escapedChar'
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
characterReference
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> Text
T.singleton (Char -> Text)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FilePath -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
noneOf FilePath
"\n"
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Text -> ParsecT Sources ParserState m Text
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
" ")
inBalancedBrackets :: PandocMonad m
=> MarkdownParser m (F a)
-> MarkdownParser m (F a)
inBalancedBrackets :: forall (m :: * -> *) a.
PandocMonad m =>
MarkdownParser m (F a) -> MarkdownParser m (F a)
inBalancedBrackets MarkdownParser m (F a)
innerParser =
MarkdownParser m (F a) -> MarkdownParser m (F a)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MarkdownParser m (F a) -> MarkdownParser m (F a))
-> MarkdownParser m (F a) -> MarkdownParser m (F a)
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'[' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ((), Text)
-> ParsecT Sources ParserState m ((), Text)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ((), Text)
forall (m :: * -> *) st a.
Monad m =>
ParsecT Sources st m a -> ParsecT Sources st m (a, Text)
withRaw (Int -> ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => Int -> MarkdownParser m ()
go Int
1) ParsecT Sources ParserState m ((), Text)
-> (((), Text) -> MarkdownParser m (F a)) -> MarkdownParser m (F a)
forall a b.
ParsecT Sources ParserState m a
-> (a -> ParsecT Sources ParserState m b)
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
MarkdownParser m (F a) -> Text -> MarkdownParser m (F a)
forall (m :: * -> *) st r.
Monad m =>
ParsecT Sources st m r -> Text -> ParsecT Sources st m r
parseFromString MarkdownParser m (F a)
innerParser (Text -> MarkdownParser m (F a))
-> (((), Text) -> Text) -> ((), Text) -> MarkdownParser m (F a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
stripBracket (Text -> Text) -> (((), Text) -> Text) -> ((), Text) -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((), Text) -> Text
forall a b. (a, b) -> b
snd
where stripBracket :: Text -> Text
stripBracket Text
t = case Text -> Maybe (Text, Char)
T.unsnoc Text
t of
Just (Text
t', Char
']') -> Text
t'
Maybe (Text, Char)
_ -> Text
t
go :: PandocMonad m => Int -> MarkdownParser m ()
go :: forall (m :: * -> *). PandocMonad m => Int -> MarkdownParser m ()
go Int
0 = () -> ParsecT Sources ParserState m ()
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
go Int
openBrackets =
(() ()
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m ()
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
escapedChar ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
code ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
math ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
endline ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
rawHtmlInline ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
rawLaTeXInline') ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => Int -> MarkdownParser m ()
go Int
openBrackets)
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
(do Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']'
Bool
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
Control.Monad.when (Int
openBrackets Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1) (ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ Int -> ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => Int -> MarkdownParser m ()
go (Int
openBrackets Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1))
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
(Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'[' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => Int -> MarkdownParser m ()
go (Int
openBrackets Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1))
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
((Char -> Bool) -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\n') ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => Int -> MarkdownParser m ()
go Int
openBrackets)
rawTitleBlockLine :: PandocMonad m => MarkdownParser m Text
rawTitleBlockLine :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
rawTitleBlockLine = do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'%'
ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
first <- ParsecT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLine
rest <- many $ try $ do spaceChar
notFollowedBy blankline
skipSpaces
anyLine
return $ trim $ T.unlines (first:rest)
titleLine :: PandocMonad m => MarkdownParser m (F Inlines)
titleLine :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
titleLine = ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
raw <- MarkdownParser m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
rawTitleBlockLine
res <- parseFromString' inlines raw
return $ trimInlinesF res
authorsLine :: PandocMonad m => MarkdownParser m (F [Inlines])
authorsLine :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (F [Inlines])
authorsLine = ParsecT Sources ParserState m (F [Inlines])
-> ParsecT Sources ParserState m (F [Inlines])
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F [Inlines])
-> ParsecT Sources ParserState m (F [Inlines]))
-> ParsecT Sources ParserState m (F [Inlines])
-> ParsecT Sources ParserState m (F [Inlines])
forall a b. (a -> b) -> a -> b
$ do
raw <- MarkdownParser m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
rawTitleBlockLine
let sep = (Char -> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
';' ParsecT Sources u m Char
-> ParsecT Sources u m () -> ParsecT Sources u m Char
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources u m ()
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces) ParsecT Sources u m Char
-> ParsecT Sources u m Char -> ParsecT Sources u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
let pAuthors = ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [F Inlines]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy
(F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many
(ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall {u}. ParsecT Sources u m Char
sep ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inline))
ParsecT Sources ParserState m Char
forall {u}. ParsecT Sources u m Char
sep
sequence <$> parseFromString' pAuthors raw
dateLine :: PandocMonad m => MarkdownParser m (F Inlines)
dateLine :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
dateLine = ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
raw <- MarkdownParser m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
rawTitleBlockLine
res <- parseFromString' inlines raw
return $ trimInlinesF res
titleBlock :: PandocMonad m => MarkdownParser m ()
titleBlock :: forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
titleBlock = MarkdownParser m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
pandocTitleBlock MarkdownParser m () -> MarkdownParser m () -> MarkdownParser m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MarkdownParser m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
mmdTitleBlock
pandocTitleBlock :: PandocMonad m => MarkdownParser m ()
pandocTitleBlock :: forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
pandocTitleBlock = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_pandoc_title_block
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'%')
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ do
title <- F Inlines
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option F Inlines
forall a. Monoid a => a
mempty ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
titleLine
author <- option (return []) authorsLine
date <- option mempty dateLine
optional blanklines
let meta' = do title' <- F Inlines
title
author' <- author
date' <- date
return $
(if null title'
then id
else B.setMeta "title" title')
. (if null author'
then id
else B.setMeta "author" author')
. (if null date'
then id
else B.setMeta "date" date')
$ nullMeta
updateState $ \ParserState
st -> ParserState
st{ stateMeta' = stateMeta' st <> meta' }
yamlMetaBlock' :: PandocMonad m => MarkdownParser m (F Blocks)
yamlMetaBlock' :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
yamlMetaBlock' = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_yaml_metadata_block
newMetaF <- ParsecT Sources ParserState m (Future ParserState MetaValue)
-> ParsecT Sources ParserState m (Future ParserState Meta)
forall st (m :: * -> *).
(HasLastStrPosition st, PandocMonad m) =>
ParsecT Sources st m (Future st MetaValue)
-> ParsecT Sources st m (Future st Meta)
yamlMetaBlock ((Blocks -> MetaValue)
-> Future ParserState Blocks -> Future ParserState MetaValue
forall a b.
(a -> b) -> Future ParserState a -> Future ParserState b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Blocks -> MetaValue
forall a. ToMetaValue a => a -> MetaValue
B.toMetaValue (Future ParserState Blocks -> Future ParserState MetaValue)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState MetaValue)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
parseBlocks)
updateState $ \ParserState
st -> ParserState
st{ stateMeta' = stateMeta' st <> newMetaF }
return mempty
mmdTitleBlock :: PandocMonad m => MarkdownParser m ()
mmdTitleBlock :: forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
mmdTitleBlock = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_mmd_title_block
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ do
firstPair <- Bool -> MarkdownParser m (Text, MetaValue)
forall (m :: * -> *).
PandocMonad m =>
Bool -> MarkdownParser m (Text, MetaValue)
kvPair Bool
False
restPairs <- many (kvPair True)
let kvPairs = (Text, MetaValue)
firstPair (Text, MetaValue) -> [(Text, MetaValue)] -> [(Text, MetaValue)]
forall a. a -> [a] -> [a]
: [(Text, MetaValue)]
restPairs
blanklines
updateState $ \ParserState
st -> ParserState
st{ stateMeta' = stateMeta' st <>
return (Meta $ M.fromList kvPairs) }
kvPair :: PandocMonad m => Bool -> MarkdownParser m (Text, MetaValue)
kvPair :: forall (m :: * -> *).
PandocMonad m =>
Bool -> MarkdownParser m (Text, MetaValue)
kvPair Bool
allowEmpty = ParsecT Sources ParserState m (Text, MetaValue)
-> ParsecT Sources ParserState m (Text, MetaValue)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Text, MetaValue)
-> ParsecT Sources ParserState m (Text, MetaValue))
-> ParsecT Sources ParserState m (Text, MetaValue)
-> ParsecT Sources ParserState m (Text, MetaValue)
forall a b. (a -> b) -> a -> b
$ do
key <- ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall end s (m :: * -> *) t st.
(Show end, Stream s m t) =>
ParsecT s st m Char -> ParsecT s st m end -> ParsecT s st m Text
many1TillChar (ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> FilePath -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
oneOf FilePath
"_- ") (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
':')
val <- trim <$> manyTillChar anyChar
(try $ newline >> lookAhead (blankline <|> nonspaceChar))
guard $ allowEmpty || not (T.null val)
let key' = [Text] -> Text
T.concat ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ Text -> [Text]
T.words (Text -> [Text]) -> Text -> [Text]
forall a b. (a -> b) -> a -> b
$ Text -> Text
T.toLower Text
key
let val' = [Inline] -> MetaValue
MetaInlines ([Inline] -> MetaValue) -> [Inline] -> MetaValue
forall a b. (a -> b) -> a -> b
$ Inlines -> [Inline]
forall a. Many a -> [a]
B.toList (Inlines -> [Inline]) -> Inlines -> [Inline]
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.text Text
val
return (key',val')
parseMarkdown :: PandocMonad m => MarkdownParser m Pandoc
parseMarkdown :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Pandoc
parseMarkdown = do
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
titleBlock
blocks <- MarkdownParser m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
parseBlocks
st <- getState
checkNotes
let doc = Future ParserState Pandoc -> ParserState -> Pandoc
forall s a. Future s a -> s -> a
runF (do Pandoc _ bs <- Blocks -> Pandoc
B.doc (Blocks -> Pandoc)
-> Future ParserState Blocks -> Future ParserState Pandoc
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Future ParserState Blocks
blocks
meta <- stateMeta' st
return $ Pandoc meta bs) ParserState
st
reportLogMessages
return doc
checkNotes :: PandocMonad m => MarkdownParser m ()
checkNotes :: forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
checkNotes = do
st <- ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
let notesUsed = ParserState -> Set Text
stateNoteRefs ParserState
st
let notesDefined = Map Text (SourcePos, Future ParserState Blocks) -> [Text]
forall k a. Map k a -> [k]
M.keys (ParserState -> Map Text (SourcePos, Future ParserState Blocks)
stateNotes' ParserState
st)
mapM_ (\Text
n -> Bool
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text
n Text -> Set Text -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` Set Text
notesUsed) (ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$
case Text
-> Map Text (SourcePos, Future ParserState Blocks)
-> Maybe (SourcePos, Future ParserState Blocks)
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
n (ParserState -> Map Text (SourcePos, Future ParserState Blocks)
stateNotes' ParserState
st) of
Just (SourcePos
pos, Future ParserState Blocks
_) -> LogMessage -> ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (Text -> SourcePos -> LogMessage
NoteDefinedButNotUsed Text
n SourcePos
pos)
Maybe (SourcePos, Future ParserState Blocks)
Nothing -> PandocError -> ParsecT Sources ParserState m ()
forall a. PandocError -> ParsecT Sources ParserState m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (PandocError -> ParsecT Sources ParserState m ())
-> PandocError -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$
Text -> PandocError
PandocShouldNeverHappenError Text
"note not found")
notesDefined
referenceKey :: PandocMonad m => MarkdownParser m (F Blocks)
referenceKey :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
referenceKey = ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks))
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ do
pos <- ParsecT Sources ParserState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
skipNonindentSpaces
notFollowedBy (void cite)
(_,raw) <- reference
char ':'
skipSpaces >> optional newline >> skipSpaces >> notFollowedBy (char '[')
let sourceURL = ([Text] -> Text)
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m Text
forall a b.
(a -> b)
-> ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Text] -> Text
T.unwords (ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text])
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ do
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
referenceTitle
ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' (ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_link_attributes ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
ParsecT Sources ParserState m Attr
forall (m :: * -> *). PandocMonad m => MarkdownParser m Attr
attributes
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' (ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_mmd_link_attributes ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m ()
forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m ()
spnl ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m (Attr -> Attr)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Attr -> Attr)
keyValAttr)
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' (() ()
-> MarkdownParser m (F Inlines, Text)
-> ParsecT Sources ParserState m ()
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ MarkdownParser m (F Inlines, Text)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (F Inlines, Text)
reference)
[Text] -> Text
forall a. Monoid a => [a] -> a
mconcat ([Text] -> Text)
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
space ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
litChar)
let betweenAngles = ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'<' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
[Text] -> Text
forall a. Monoid a => [a] -> a
mconcat ([Text] -> Text)
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Text]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
manyTill ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
litChar (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'>'))
rebase <- option False (True <$ guardEnabled Ext_rebase_relative_paths)
src <- (if rebase then rebasePath pos else id) <$>
(try betweenAngles <|> sourceURL)
tit <- option "" referenceTitle
attr <- option nullAttr $ try $
do guardEnabled Ext_link_attributes
skipSpaces >> optional newline >> skipSpaces
attributes
addKvs <- option [] $ guardEnabled Ext_mmd_link_attributes
>> many (try $ spnl >> keyValAttr)
blanklines
let attr' = Attr -> Attr
extractIdClass (Attr -> Attr) -> Attr -> Attr
forall a b. (a -> b) -> a -> b
$ (Attr -> (Attr -> Attr) -> Attr) -> Attr -> [Attr -> Attr] -> Attr
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\Attr
x Attr -> Attr
f -> Attr -> Attr
f Attr
x) Attr
attr [Attr -> Attr]
addKvs
target = (Text -> Text
escapeURI (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Text
trimr Text
src, Text
tit)
st <- getState
let oldkeys = ParserState -> KeyTable
stateKeys ParserState
st
let key = Text -> Key
toKey Text
raw
case M.lookup key oldkeys of
Just (Target
t,Attr
a) | Bool -> Bool
not (Target
t Target -> Target -> Bool
forall a. Eq a => a -> a -> Bool
== Target
target Bool -> Bool -> Bool
&& Attr
a Attr -> Attr -> Bool
forall a. Eq a => a -> a -> Bool
== Attr
attr') ->
LogMessage -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasLogMessages st) =>
LogMessage -> ParsecT s st m ()
logMessage (LogMessage -> ParsecT Sources ParserState m ())
-> LogMessage -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
DuplicateLinkReference Text
raw SourcePos
pos
Maybe (Target, Attr)
_ -> () -> ParsecT Sources ParserState m ()
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
updateState $ \ParserState
s -> ParserState
s { stateKeys = M.insert key (target, attr') oldkeys }
return $ return mempty
referenceTitle :: PandocMonad m => MarkdownParser m Text
referenceTitle :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
referenceTitle = ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ do
ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
Char -> ParsecT Sources ParserState m Text
forall (m :: * -> *).
PandocMonad m =>
Char -> MarkdownParser m Text
quotedTitle Char
'"' ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParsecT Sources ParserState m Text
forall (m :: * -> *).
PandocMonad m =>
Char -> MarkdownParser m Text
quotedTitle Char
'\'' ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char
-> Char
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
Char -> Char -> ParsecT s st m Text -> ParsecT s st m Text
charsInBalanced Char
'(' Char
')' ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
litChar
quotedTitle :: PandocMonad m => Char -> MarkdownParser m Text
quotedTitle :: forall (m :: * -> *).
PandocMonad m =>
Char -> MarkdownParser m Text
quotedTitle Char
c = ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m ()
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces
let pEnder :: ParsecT Sources u m ()
pEnder = ParsecT Sources u m () -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources u m () -> ParsecT Sources u m ())
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c ParsecT Sources u m Char
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m Char -> ParsecT Sources u m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ((Char -> Bool) -> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isAlphaNum)
let regChunk :: ParsecT Sources ParserState m Text
regChunk = ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char (FilePath -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
noneOf [Char
'\\',Char
'\n',Char
'&',Char
c]) ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
litChar
let nestedChunk :: ParsecT Sources ParserState m Text
nestedChunk = (\Text
x -> (Char
c Char -> Text -> Text
`T.cons` Text
x) Text -> Char -> Text
`T.snoc` Char
c) (Text -> Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char -> ParsecT Sources ParserState m Text
forall (m :: * -> *).
PandocMonad m =>
Char -> MarkdownParser m Text
quotedTitle Char
c
[Text] -> Text
T.unwords ([Text] -> Text) -> ([Text] -> [Text]) -> [Text] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Text]
T.words (Text -> [Text]) -> ([Text] -> Text) -> [Text] -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Text
T.concat ([Text] -> Text)
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m [Text]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
manyTill (ParsecT Sources ParserState m Text
nestedChunk ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Text
regChunk) ParsecT Sources ParserState m ()
forall {u}. ParsecT Sources u m ()
pEnder
abbrevKey :: PandocMonad m => MarkdownParser m (F Blocks)
abbrevKey :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
abbrevKey = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_abbreviations
ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks))
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'*'
MarkdownParser m (F Inlines, Text)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (F Inlines, Text)
reference
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
':'
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ((Char -> Bool) -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\n'))
ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
blanklines
Future ParserState Blocks
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Future ParserState Blocks
-> ParsecT Sources ParserState m (Future ParserState Blocks))
-> Future ParserState Blocks
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ Blocks -> Future ParserState Blocks
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty
noteMarker :: PandocMonad m => MarkdownParser m Text
noteMarker :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
noteMarker = FilePath -> ParsecT Sources ParserState m 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 m FilePath
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall end s (m :: * -> *) t st.
(Show end, Stream s m t) =>
ParsecT s st m Char -> ParsecT s st m end -> ParsecT s st m Text
many1TillChar ((Char -> Bool) -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (Char -> FilePath -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Char
'\r',Char
'\n',Char
'\t',Char
' ',Char
'^',Char
'[',Char
']']))
(Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']')
rawLine :: PandocMonad m => MarkdownParser m Text
rawLine :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
rawLine = ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ do
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
notFollowedByDivCloser
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ MarkdownParser m Int
forall (m :: * -> *). PandocMonad m => MarkdownParser m Int
skipNonindentSpaces MarkdownParser m Int
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
noteMarker
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
indentSpaces
ParsecT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLine
rawLines :: PandocMonad m => MarkdownParser m Text
rawLines :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
rawLines = do
first <- ParsecT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLine
rest <- many rawLine
return $ T.unlines (first:rest)
noteBlock :: PandocMonad m => MarkdownParser m (F Blocks)
noteBlock :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
noteBlock = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_footnotes
ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks))
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ do
pos <- ParsecT Sources ParserState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
skipNonindentSpaces
ref <- noteMarker
char ':'
optional blankline
optional indentSpaces
updateState $ \ParserState
st -> ParserState
st{ stateInNote = True }
first <- rawLines
rest <- many $ try $ blanklines >> indentSpaces >> rawLines
let raw = [Text] -> Text
T.unlines (Text
firstText -> [Text] -> [Text]
forall a. a -> [a] -> [a]
:[Text]
rest) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n"
optional blanklines
parsed <- parseFromString' parseBlocks raw
oldnotes <- stateNotes' <$> getState
case M.lookup ref oldnotes of
Just (SourcePos, Future ParserState Blocks)
_ -> LogMessage -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasLogMessages st) =>
LogMessage -> ParsecT s st m ()
logMessage (LogMessage -> ParsecT Sources ParserState m ())
-> LogMessage -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
DuplicateNoteReference Text
ref SourcePos
pos
Maybe (SourcePos, Future ParserState Blocks)
Nothing -> () -> ParsecT Sources ParserState m ()
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
updateState $ \ParserState
s -> ParserState
s { stateNotes' =
M.insert ref (pos, parsed) oldnotes,
stateInNote = False }
return mempty
parseBlocks :: PandocMonad m => MarkdownParser m (F Blocks)
parseBlocks :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
parseBlocks = [Future ParserState Blocks] -> Future ParserState Blocks
forall a. Monoid a => [a] -> a
mconcat ([Future ParserState Blocks] -> Future ParserState Blocks)
-> ParsecT Sources ParserState m [Future ParserState Blocks]
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m [Future ParserState Blocks]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
manyTill ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
block ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
block :: PandocMonad m => MarkdownParser m (F Blocks)
block :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
block = do
res <- [ParsecT Sources ParserState m (Future ParserState Blocks)]
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ Future ParserState Blocks
forall a. Monoid a => a
mempty Future ParserState Blocks
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
blanklines
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
codeBlockFenced
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
yamlMetaBlock'
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
bulletList
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
divHtml
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
divFenced
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
header
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
lhsCodeBlock
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
htmlBlock
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
table
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
codeBlockIndented
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
rawTeXBlock
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
lineBlock
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
blockQuote
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *) st.
PandocMonad m =>
ParsecT Sources st m (Future ParserState Blocks)
hrule
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
orderedList
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
definitionList
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
noteBlock
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
referenceKey
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
abbrevKey
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
para
, ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
plain
] ParsecT Sources ParserState m (Future ParserState Blocks)
-> FilePath
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> FilePath -> ParsecT s u m a
<?> FilePath
"block"
trace (T.take 60 $ tshow $ B.toList $ runF res defaultParserState)
return res
header :: PandocMonad m => MarkdownParser m (F Blocks)
= MarkdownParser m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
setextHeader MarkdownParser m (Future ParserState Blocks)
-> MarkdownParser m (Future ParserState Blocks)
-> MarkdownParser m (Future ParserState Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MarkdownParser m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
atxHeader MarkdownParser m (Future ParserState Blocks)
-> FilePath -> MarkdownParser m (Future ParserState Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> FilePath -> ParsecT s u m a
<?> FilePath
"header"
atxChar :: PandocMonad m => MarkdownParser m Char
atxChar :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Char
atxChar = do
exts <- (ReaderOptions -> Extensions)
-> ParsecT Sources ParserState m Extensions
forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParsecT s st m b
forall s (m :: * -> *) t b.
Stream s m t =>
(ReaderOptions -> b) -> ParsecT s ParserState m b
getOption ReaderOptions -> Extensions
readerExtensions
return $ if extensionEnabled Ext_literate_haskell exts
then '='
else '#'
atxHeader :: PandocMonad m => MarkdownParser m (F Blocks)
= ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks))
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ do
level <- (FilePath -> Int)
-> ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m Int
forall a b.
(a -> b)
-> ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap FilePath -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (MarkdownParser m Char
forall (m :: * -> *). PandocMonad m => MarkdownParser m Char
atxChar MarkdownParser m Char
-> (Char -> ParsecT Sources ParserState m FilePath)
-> ParsecT Sources ParserState m FilePath
forall a b.
ParsecT Sources ParserState m a
-> (a -> ParsecT Sources ParserState m b)
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MarkdownParser m Char -> ParsecT Sources ParserState m FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (MarkdownParser m Char -> ParsecT Sources ParserState m FilePath)
-> (Char -> MarkdownParser m Char)
-> Char
-> ParsecT Sources ParserState m FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> MarkdownParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char)
notFollowedBy $ guardEnabled Ext_fancy_lists >>
(char '.' <|> char ')')
guardDisabled Ext_space_in_atx_header <|> notFollowedBy nonspaceChar
skipSpaces
(text, raw) <- withRaw $ do
oldAllowLineBreaks <- stateAllowLineBreaks <$> getState
updateState $ \ParserState
st -> ParserState
st{ stateAllowLineBreaks = False }
res <- trimInlinesF . mconcat <$>
many (notFollowedBy atxClosing >> inline)
updateState $ \ParserState
st -> ParserState
st{ stateAllowLineBreaks = oldAllowLineBreaks }
return res
attr <- atxClosing
attr' <- registerHeader attr (runF text defaultParserState)
guardDisabled Ext_implicit_header_references
<|> registerImplicitHeader raw attr'
return $ B.headerWith attr' level <$> text
atxClosing :: PandocMonad m => MarkdownParser m Attr
atxClosing :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Attr
atxClosing = ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr)
-> ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
forall a b. (a -> b) -> a -> b
$ do
attr' <- Attr
-> ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Attr
nullAttr
(Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_mmd_header_identifiers ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Attr
forall (m :: * -> *). PandocMonad m => MarkdownParser m Attr
mmdHeaderIdentifier)
skipMany . char =<< atxChar
skipSpaces
attr <- option attr'
(guardEnabled Ext_header_attributes >> attributes)
blanklines
return attr
setextHeaderEnd :: PandocMonad m => MarkdownParser m Attr
= ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr)
-> ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
forall a b. (a -> b) -> a -> b
$ do
attr <- Attr
-> ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Attr
nullAttr
(ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr)
-> ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
forall a b. (a -> b) -> a -> b
$ (Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_mmd_header_identifiers ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Attr
forall (m :: * -> *). PandocMonad m => MarkdownParser m Attr
mmdHeaderIdentifier)
ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_header_attributes ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Attr
forall (m :: * -> *). PandocMonad m => MarkdownParser m Attr
attributes)
blanklines
return attr
mmdHeaderIdentifier :: PandocMonad m => MarkdownParser m Attr
= do
(_, raw) <- MarkdownParser m (F Inlines, Text)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (F Inlines, Text)
reference
let raw' = Text -> Text
trim (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Text
stripFirstAndLast Text
raw
let ident = [Text] -> Text
T.concat ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ Text -> [Text]
T.words (Text -> [Text]) -> Text -> [Text]
forall a b. (a -> b) -> a -> b
$ Text -> Text
T.toLower Text
raw'
let attr = (Text
ident, [], [])
guardDisabled Ext_implicit_header_references
<|> registerImplicitHeader raw' attr
skipSpaces
return attr
setextHeader :: PandocMonad m => MarkdownParser m (F Blocks)
= ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks))
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ do
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLine ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m FilePath
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (FilePath -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
oneOf FilePath
setextHChars) ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
(text, raw) <- ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines, Text)
forall (m :: * -> *) st a.
Monad m =>
ParsecT Sources st m a -> ParsecT Sources st m (a, Text)
withRaw (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines, Text))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines, Text)
forall a b. (a -> b) -> a -> b
$ do
oldAllowLineBreaks <- ParserState -> Bool
stateAllowLineBreaks (ParserState -> Bool)
-> ParsecT Sources ParserState m ParserState
-> ParsecT Sources ParserState m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
updateState $ \ParserState
st -> ParserState
st{ stateAllowLineBreaks = False }
res <- trimInlinesF . mconcat <$>
many (notFollowedBy setextHeaderEnd >> inline)
updateState $ \ParserState
st -> ParserState
st{ stateAllowLineBreaks = oldAllowLineBreaks }
return res
attr <- setextHeaderEnd
underlineChar <- oneOf setextHChars
many (char underlineChar)
blanklines
let level = Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
0 (Char -> FilePath -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
elemIndex Char
underlineChar FilePath
setextHChars) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
attr' <- registerHeader attr (runF text defaultParserState)
guardDisabled Ext_implicit_header_references
<|> registerImplicitHeader raw attr'
return $ B.headerWith attr' level <$> text
registerImplicitHeader :: PandocMonad m => Text -> Attr -> MarkdownParser m ()
Text
raw attr :: Attr
attr@(Text
ident, [Text]
_, [Target]
_)
| Text -> Bool
T.null Text
raw = () -> ParsecT Sources ParserState m ()
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = do
let key :: Key
key = Text -> Key
toKey (Text -> Key) -> Text -> Key
forall a b. (a -> b) -> a -> b
$ Text
"[" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
raw Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"]"
(ParserState -> ParserState) -> ParsecT Sources ParserState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((ParserState -> ParserState) -> ParsecT Sources ParserState m ())
-> (ParserState -> ParserState) -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ \ParserState
s ->
ParserState
s { stateHeaderKeys = M.insertWith (\(Target, Attr)
_new (Target, Attr)
old -> (Target, Attr)
old)
key (("#" <> ident,""), attr)
(stateHeaderKeys s) }
hrule :: PandocMonad m => ParsecT Sources st m (F Blocks)
hrule :: forall (m :: * -> *) st.
PandocMonad m =>
ParsecT Sources st m (Future ParserState Blocks)
hrule = ParsecT Sources st m (Future ParserState Blocks)
-> ParsecT Sources st m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources st m (Future ParserState Blocks)
-> ParsecT Sources st m (Future ParserState Blocks))
-> ParsecT Sources st m (Future ParserState Blocks)
-> ParsecT Sources st m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ do
ParsecT Sources st m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
start <- (Char -> Bool) -> ParsecT Sources st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isHruleChar
count 2 (skipSpaces >> char start)
skipMany (spaceChar <|> char start)
newline
optional blanklines
return $ return B.horizontalRule
indentedLine :: PandocMonad m => MarkdownParser m Text
indentedLine :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
indentedLine = MarkdownParser m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
indentSpaces MarkdownParser m Text
-> MarkdownParser m Text -> MarkdownParser m Text
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> MarkdownParser m Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLineNewline
blockDelimiter :: PandocMonad m
=> (Char -> Bool)
-> Maybe Int
-> ParsecT Sources ParserState m Int
blockDelimiter :: forall (m :: * -> *).
PandocMonad m =>
(Char -> Bool) -> Maybe Int -> ParsecT Sources ParserState m Int
blockDelimiter Char -> Bool
f Maybe Int
len = ParsecT Sources ParserState m Int
-> ParsecT Sources ParserState m Int
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Int
-> ParsecT Sources ParserState m Int)
-> ParsecT Sources ParserState m Int
-> ParsecT Sources ParserState m Int
forall a b. (a -> b) -> a -> b
$ do
ParsecT Sources ParserState m Int
forall (m :: * -> *). PandocMonad m => MarkdownParser m Int
skipNonindentSpaces
c <- ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ((Char -> Bool) -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
f)
case len of
Just Int
l -> Int
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m FilePath
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
l (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c) ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m FilePath
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c) ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m Int
-> ParsecT Sources ParserState m Int
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> ParsecT Sources ParserState m Int
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Int
l
Maybe Int
Nothing -> (FilePath -> Int)
-> ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m Int
forall a b.
(a -> b)
-> ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3) (Int -> Int) -> (FilePath -> Int) -> FilePath -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length) (Int
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m FilePath
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
3 (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c) ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m FilePath
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c))
attributes :: PandocMonad m => MarkdownParser m Attr
attributes :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Attr
attributes = ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr)
-> ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'{'
ParsecT Sources ParserState m ()
forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m ()
spnl
attrs <- ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m [Attr -> Attr]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT Sources ParserState m (Attr -> Attr)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Attr -> Attr)
attribute ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (Attr -> Attr)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m ()
forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m ()
spnl)
char '}'
return $ foldl' (\Attr
x Attr -> Attr
f -> Attr -> Attr
f Attr
x) nullAttr attrs
attribute :: PandocMonad m => MarkdownParser m (Attr -> Attr)
attribute :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Attr -> Attr)
attribute = MarkdownParser m (Attr -> Attr)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Attr -> Attr)
identifierAttr MarkdownParser m (Attr -> Attr)
-> MarkdownParser m (Attr -> Attr)
-> MarkdownParser m (Attr -> Attr)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MarkdownParser m (Attr -> Attr)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Attr -> Attr)
classAttr MarkdownParser m (Attr -> Attr)
-> MarkdownParser m (Attr -> Attr)
-> MarkdownParser m (Attr -> Attr)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MarkdownParser m (Attr -> Attr)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Attr -> Attr)
keyValAttr MarkdownParser m (Attr -> Attr)
-> MarkdownParser m (Attr -> Attr)
-> MarkdownParser m (Attr -> Attr)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MarkdownParser m (Attr -> Attr)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Attr -> Attr)
specialAttr
identifier :: PandocMonad m => MarkdownParser m Text
identifier :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
identifier = do
first <- ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
letter
rest <- many $ alphaNum <|> oneOf "-_:."
return $ T.pack (first:rest)
identifierAttr :: PandocMonad m => MarkdownParser m (Attr -> Attr)
identifierAttr :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Attr -> Attr)
identifierAttr = ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr))
-> ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr)
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'#'
result <- FilePath -> Text
T.pack (FilePath -> Text)
-> ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> FilePath -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
oneOf FilePath
"-_:.")
return $ \(Text
_,[Text]
cs,[Target]
kvs) -> (Text
result,[Text]
cs,[Target]
kvs)
classAttr :: PandocMonad m => MarkdownParser m (Attr -> Attr)
classAttr :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Attr -> Attr)
classAttr = ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr))
-> ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr)
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'.'
result <- MarkdownParser m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
identifier
return $ \(Text
id',[Text]
cs,[Target]
kvs) -> (Text
id',[Text]
cs [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [Text
result],[Target]
kvs)
keyValAttr :: PandocMonad m => MarkdownParser m (Attr -> Attr)
keyValAttr :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Attr -> Attr)
keyValAttr = ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr))
-> ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr)
forall a b. (a -> b) -> a -> b
$ do
key <- MarkdownParser m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
identifier
char '='
val <- mconcat <$> enclosed (char '"') (char '"') litChar
<|> mconcat <$> enclosed (char '\'') (char '\'') litChar
<|> ("" <$ try (string "\"\""))
<|> ("" <$ try (string "''"))
<|> manyChar (escapedChar' <|> noneOf " \t\n\r}")
return $ \(Text
id',[Text]
cs,[Target]
kvs) ->
case Text
key of
Text
"id" -> (Text
val,[Text]
cs,[Target]
kvs)
Text
"class" -> (Text
id',[Text]
cs [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ Text -> [Text]
T.words Text
val,[Target]
kvs)
Text
_ -> (Text
id',[Text]
cs,[Target]
kvs [Target] -> [Target] -> [Target]
forall a. [a] -> [a] -> [a]
++ [(Text
key,Text
val)])
specialAttr :: PandocMonad m => MarkdownParser m (Attr -> Attr)
specialAttr :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Attr -> Attr)
specialAttr = do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'-'
(Attr -> Attr) -> ParsecT Sources ParserState m (Attr -> Attr)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Attr -> Attr) -> ParsecT Sources ParserState m (Attr -> Attr))
-> (Attr -> Attr) -> ParsecT Sources ParserState m (Attr -> Attr)
forall a b. (a -> b) -> a -> b
$ \(Text
id',[Text]
cs,[Target]
kvs) -> (Text
id',[Text]
cs [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [Text
"unnumbered"],[Target]
kvs)
rawAttribute :: PandocMonad m => MarkdownParser m Text
rawAttribute :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
rawAttribute = do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'{'
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'='
format <- ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (\Char
c -> Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char
c Char -> FilePath -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char
'-', Char
'_'])
skipMany spaceChar
char '}'
return format
codeBlockFenced :: PandocMonad m => MarkdownParser m (F Blocks)
codeBlockFenced :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
codeBlockFenced = ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks))
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ do
indentchars <- MarkdownParser m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
nonindentSpaces
let indentLevel = Text -> Int
T.length Text
indentchars
c <- (guardEnabled Ext_fenced_code_blocks >> lookAhead (char '~'))
<|> (guardEnabled Ext_backtick_code_blocks >> lookAhead (char '`'))
size <- blockDelimiter (== c) Nothing
skipMany spaceChar
rawattr <-
(Left <$> (guardEnabled Ext_raw_attribute >> try rawAttribute))
<|>
(Right <$> do
let pLangId = ParsecT Sources st m Char -> ParsecT Sources st m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char (ParsecT Sources st m Char -> ParsecT Sources st m Text)
-> ((Char -> Bool) -> ParsecT Sources st m Char)
-> (Char -> Bool)
-> ParsecT Sources st m Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> ParsecT Sources st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy ((Char -> Bool) -> ParsecT Sources st m Text)
-> (Char -> Bool) -> ParsecT Sources st m Text
forall a b. (a -> b) -> a -> b
$ \Char
x ->
Char
x Char -> FilePath -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Char
'`', Char
'{', Char
'}'] Bool -> Bool -> Bool
&& Bool -> Bool
not (Char -> Bool
isSpace Char
x)
mbLanguageId <- optionMaybe (toLanguageId <$> pLangId)
skipMany spaceChar
mbAttr <- optionMaybe
(guardEnabled Ext_fenced_code_attributes *> try attributes)
return $ case mbAttr of
Maybe Attr
Nothing -> (Text
"", Maybe Text -> [Text]
forall a. Maybe a -> [a]
maybeToList Maybe Text
mbLanguageId, [])
Just (Text
elementId, [Text]
classes, [Target]
attrs) ->
(Text
elementId, (([Text] -> [Text])
-> (Text -> [Text] -> [Text]) -> Maybe Text -> [Text] -> [Text]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Text] -> [Text]
forall a. a -> a
id (:) Maybe Text
mbLanguageId) [Text]
classes, [Target]
attrs))
blankline
contents <- T.intercalate "\n" <$>
manyTill (gobbleAtMostSpaces indentLevel >> anyLine)
(try $ do
blockDelimiter (== c) (Just size)
blanklines)
return $ return $
case rawattr of
Left Text
syn -> Text -> Text -> Blocks
B.rawBlock Text
syn Text
contents
Right Attr
attr -> Attr -> Text -> Blocks
B.codeBlockWith Attr
attr Text
contents
toLanguageId :: Text -> Text
toLanguageId :: Text -> Text
toLanguageId = Text -> Text
T.toLower (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
forall {a}. (Eq a, IsString a) => a -> a
go
where go :: a -> a
go a
"c++" = a
"cpp"
go a
"objective-c" = a
"objectivec"
go a
x = a
x
codeBlockIndented :: PandocMonad m => MarkdownParser m (F Blocks)
codeBlockIndented :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
codeBlockIndented = do
contents <- ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
indentedLine ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (do b <- ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
blanklines
l <- indentedLine
return $ b <> l))
optional blanklines
classes <- getOption readerIndentedCodeClasses
return $ return $ B.codeBlockWith ("", classes, []) $
stripTrailingNewlines $ T.concat contents
lhsCodeBlock :: PandocMonad m => MarkdownParser m (F Blocks)
lhsCodeBlock :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
lhsCodeBlock = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_literate_haskell
(Blocks -> Future ParserState Blocks
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> Future ParserState Blocks)
-> (Text -> Blocks) -> Text -> Future ParserState Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Attr -> Text -> Blocks
B.codeBlockWith (Text
"",[Text
"haskell",Text
"literate"],[]) (Text -> Future ParserState Blocks)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
lhsCodeBlockBird ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
lhsCodeBlockLaTeX))
ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Blocks -> Future ParserState Blocks
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> Future ParserState Blocks)
-> (Text -> Blocks) -> Text -> Future ParserState Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Attr -> Text -> Blocks
B.codeBlockWith (Text
"",[Text
"haskell"],[]) (Text -> Future ParserState Blocks)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
lhsCodeBlockInverseBird)
lhsCodeBlockLaTeX :: PandocMonad m => MarkdownParser m Text
lhsCodeBlockLaTeX :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
lhsCodeBlockLaTeX = ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ do
FilePath -> ParsecT Sources ParserState m FilePath
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m FilePath
string FilePath
"\\begin{code}"
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m FilePath
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
manyTill ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
contents <- ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m Text
forall end s (m :: * -> *) t st.
(Show end, Stream s m t) =>
ParsecT s st m Char -> ParsecT s st m end -> ParsecT s st m Text
many1TillChar ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m FilePath)
-> ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m FilePath
forall a b. (a -> b) -> a -> b
$ FilePath -> ParsecT Sources ParserState m FilePath
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m FilePath
string FilePath
"\\end{code}")
blanklines
return $ stripTrailingNewlines contents
lhsCodeBlockBird :: PandocMonad m => MarkdownParser m Text
lhsCodeBlockBird :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
lhsCodeBlockBird = Char -> MarkdownParser m Text
forall (m :: * -> *).
PandocMonad m =>
Char -> MarkdownParser m Text
lhsCodeBlockBirdWith Char
'>'
lhsCodeBlockInverseBird :: PandocMonad m => MarkdownParser m Text
lhsCodeBlockInverseBird :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
lhsCodeBlockInverseBird = Char -> MarkdownParser m Text
forall (m :: * -> *).
PandocMonad m =>
Char -> MarkdownParser m Text
lhsCodeBlockBirdWith Char
'<'
lhsCodeBlockBirdWith :: PandocMonad m => Char -> MarkdownParser m Text
lhsCodeBlockBirdWith :: forall (m :: * -> *).
PandocMonad m =>
Char -> MarkdownParser m Text
lhsCodeBlockBirdWith Char
c = ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ do
pos <- ParsecT Sources ParserState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
when (sourceColumn pos /= 1) $ Prelude.fail "Not in first column"
lns <- many1 $ birdTrackLine c
let lns' = if (Text -> Bool) -> [Text] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\Text
ln -> Text -> Bool
T.null Text
ln Bool -> Bool -> Bool
|| Int -> Text -> Text
T.take Int
1 Text
ln Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
" ") [Text]
lns
then (Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Text -> Text
T.drop Int
1) [Text]
lns
else [Text]
lns
blanklines
return $ T.intercalate "\n" lns'
birdTrackLine :: PandocMonad m => Char -> ParsecT Sources st m Text
birdTrackLine :: forall (m :: * -> *) st.
PandocMonad m =>
Char -> ParsecT Sources st m Text
birdTrackLine Char
c = ParsecT Sources st m Text -> ParsecT Sources st m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources st m Text -> ParsecT Sources st m Text)
-> ParsecT Sources st m Text -> ParsecT Sources st m Text
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Sources st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c
Bool -> ParsecT Sources st m () -> ParsecT Sources st m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'<') (ParsecT Sources st m () -> ParsecT Sources st m ())
-> ParsecT Sources st m () -> ParsecT Sources st m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Sources st m Char -> ParsecT Sources st m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
letter
ParsecT Sources st m Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLine
emailBlockQuoteStart :: PandocMonad m => MarkdownParser m Char
emailBlockQuoteStart :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Char
emailBlockQuoteStart = ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b. (a -> b) -> a -> b
$ MarkdownParser m Int
forall (m :: * -> *). PandocMonad m => MarkdownParser m Int
skipNonindentSpaces MarkdownParser m Int
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'>' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Char
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
' ')
emailBlockQuote :: PandocMonad m => MarkdownParser m [Text]
emailBlockQuote :: forall (m :: * -> *). PandocMonad m => MarkdownParser m [Text]
emailBlockQuote = ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m [Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m [Text])
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m [Text]
forall a b. (a -> b) -> a -> b
$ do
MarkdownParser m Char
forall (m :: * -> *). PandocMonad m => MarkdownParser m Char
emailBlockQuoteStart
let emailLine :: ParsecT Sources ParserState m Text
emailLine = MarkdownParser m Char -> ParsecT Sources ParserState m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
manyChar (MarkdownParser m Char -> ParsecT Sources ParserState m Text)
-> MarkdownParser m Char -> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ MarkdownParser m Char
forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m Char
nonEndline MarkdownParser m Char
-> MarkdownParser m Char -> MarkdownParser m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MarkdownParser m Char -> MarkdownParser m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try
(MarkdownParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
endline MarkdownParser m (F Inlines)
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> MarkdownParser m Char -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy MarkdownParser m Char
forall (m :: * -> *). PandocMonad m => MarkdownParser m Char
emailBlockQuoteStart ParsecT Sources ParserState m ()
-> MarkdownParser m Char -> MarkdownParser m Char
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
Char -> MarkdownParser m Char
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Char
'\n')
let emailSep :: MarkdownParser m Char
emailSep = MarkdownParser m Char -> MarkdownParser m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MarkdownParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline MarkdownParser m Char
-> MarkdownParser m Char -> MarkdownParser m Char
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> MarkdownParser m Char
forall (m :: * -> *). PandocMonad m => MarkdownParser m Char
emailBlockQuoteStart)
first <- ParsecT Sources ParserState m Text
emailLine
rest <- many $ try $ emailSep >> emailLine
let raw = Text
firstText -> [Text] -> [Text]
forall a. a -> [a] -> [a]
:[Text]
rest
newline <|> (eof >> return '\n')
optional blanklines
return raw
blockQuote :: PandocMonad m => MarkdownParser m (F Blocks)
blockQuote :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
blockQuote = do
raw <- MarkdownParser m [Text]
forall (m :: * -> *). PandocMonad m => MarkdownParser m [Text]
emailBlockQuote
contents <- parseFromString' parseBlocks $ T.intercalate "\n" raw <> "\n\n"
return $ B.blockQuote <$> contents
bulletListStart :: PandocMonad m => MarkdownParser m ()
bulletListStart :: forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
bulletListStart = ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ do
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
MarkdownParser m Int
forall (m :: * -> *). PandocMonad m => MarkdownParser m Int
skipNonindentSpaces
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' (() ()
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m ()
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *) st.
PandocMonad m =>
ParsecT Sources st m (Future ParserState Blocks)
hrule)
(Char -> Bool) -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isBulletListMarker
Int -> ParsecT Sources ParserState m ()
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
Int -> ParsecT Sources st m ()
gobbleSpaces Int
1 ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () ()
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Int -> MarkdownParser m Int
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
Int -> ParsecT Sources st m Int
gobbleAtMostSpaces Int
3 MarkdownParser m Int
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar) ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () -> ParsecT Sources ParserState m ()
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
orderedListStart :: PandocMonad m
=> Maybe (ListNumberStyle, ListNumberDelim)
-> MarkdownParser m (Int, ListNumberStyle, ListNumberDelim)
orderedListStart :: forall (m :: * -> *).
PandocMonad m =>
Maybe (ListNumberStyle, ListNumberDelim)
-> MarkdownParser m (Int, ListNumberStyle, ListNumberDelim)
orderedListStart Maybe (ListNumberStyle, ListNumberDelim)
mbstydelim = ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim)
-> ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim)
-> ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim))
-> ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim)
-> ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim)
forall a b. (a -> b) -> a -> b
$ do
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
MarkdownParser m Int
forall (m :: * -> *). PandocMonad m => MarkdownParser m Int
skipNonindentSpaces
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ FilePath -> ParsecT Sources ParserState m FilePath
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m FilePath
string FilePath
"p." ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
digit
(do Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardDisabled Extension
Ext_fancy_lists
start <- ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
digit ParsecT Sources ParserState m Text
-> (Text -> MarkdownParser m Int) -> MarkdownParser m Int
forall a b.
ParsecT Sources ParserState m a
-> (a -> ParsecT Sources ParserState m b)
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> MarkdownParser m Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead
char '.'
gobbleSpaces 1 <|> () <$ lookAhead newline
optional $ try (gobbleAtMostSpaces 3 >> notFollowedBy spaceChar)
return (start, DefaultStyle, DefaultDelim))
ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim)
-> ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim)
-> ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
(do (num, style, delim) <- ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim)
-> ((ListNumberStyle, ListNumberDelim)
-> ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim))
-> Maybe (ListNumberStyle, ListNumberDelim)
-> ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim)
forall s (m :: * -> *).
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s ParserState m (Int, ListNumberStyle, ListNumberDelim)
anyOrderedListMarker
(\(ListNumberStyle
sty,ListNumberDelim
delim) -> (\Int
start -> (Int
start,ListNumberStyle
sty,ListNumberDelim
delim)) (Int -> (Int, ListNumberStyle, ListNumberDelim))
-> MarkdownParser m Int
-> ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
ListNumberStyle -> ListNumberDelim -> MarkdownParser m Int
forall s (m :: * -> *).
(Stream s m Char, UpdateSourcePos s Char) =>
ListNumberStyle -> ListNumberDelim -> ParsecT s ParserState m Int
orderedListMarker ListNumberStyle
sty ListNumberDelim
delim)
Maybe (ListNumberStyle, ListNumberDelim)
mbstydelim
gobbleSpaces 1 <|> () <$ lookAhead newline
when (delim == Period && (style == UpperAlpha ||
(style == UpperRoman &&
num `elem` [1, 5, 10, 50, 100, 500, 1000]))) $
() <$ lookAhead (newline <|> spaceChar)
optional $ try (gobbleAtMostSpaces 3 >> notFollowedBy spaceChar)
return (num, style, delim))
listStart :: PandocMonad m => MarkdownParser m ()
listStart :: forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
listStart = MarkdownParser m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
bulletListStart MarkdownParser m () -> MarkdownParser m () -> MarkdownParser m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim)
-> MarkdownParser m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
Control.Monad.void (Maybe (ListNumberStyle, ListNumberDelim)
-> ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim)
forall (m :: * -> *).
PandocMonad m =>
Maybe (ListNumberStyle, ListNumberDelim)
-> MarkdownParser m (Int, ListNumberStyle, ListNumberDelim)
orderedListStart Maybe (ListNumberStyle, ListNumberDelim)
forall a. Maybe a
Nothing)
listLine :: PandocMonad m => Int -> MarkdownParser m Text
listLine :: forall (m :: * -> *). PandocMonad m => Int -> MarkdownParser m Text
listLine Int
continuationIndent = ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ do
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' (do Int -> ParsecT Sources ParserState m ()
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
Int -> ParsecT Sources st m ()
gobbleSpaces Int
continuationIndent
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
listStart)
ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
notFollowedByHtmlCloser
ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
notFollowedByDivCloser
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (() ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Int -> ParsecT Sources ParserState m ()
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
Int -> ParsecT Sources st m ()
gobbleSpaces Int
continuationIndent)
ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
listLineCommon
listLineCommon :: PandocMonad m => MarkdownParser m Text
listLineCommon :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
listLineCommon = [Text] -> Text
T.concat ([Text] -> Text)
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Text]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
manyTill
( ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char ((Char -> Bool) -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy ((Char -> Bool) -> ParsecT Sources ParserState m Char)
-> (Char -> Bool) -> ParsecT Sources ParserState m Char
forall a b. (a -> b) -> a -> b
$ \Char
c -> Char
c Char -> FilePath -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Char
'\n', Char
'<', Char
'`'])
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ((F Inlines, Text) -> Text)
-> ParsecT Sources ParserState m (F Inlines, Text)
-> ParsecT Sources ParserState m Text
forall a b.
(a -> b)
-> ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (F Inlines, Text) -> Text
forall a b. (a, b) -> b
snd (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines, Text)
forall (m :: * -> *) st a.
Monad m =>
ParsecT Sources st m a -> ParsecT Sources st m (a, Text)
withRaw ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
code)
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ((Tag Text, Text) -> Text)
-> ParsecT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m Text
forall a b.
(a -> b)
-> ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([Tag Text] -> Text
forall str. StringLike str => [Tag str] -> str
renderTags ([Tag Text] -> Text)
-> ((Tag Text, Text) -> [Tag Text]) -> (Tag Text, Text) -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Tag Text -> [Tag Text] -> [Tag Text]
forall a. a -> [a] -> [a]
:[]) (Tag Text -> [Tag Text])
-> ((Tag Text, Text) -> Tag Text) -> (Tag Text, Text) -> [Tag Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Tag Text, Text) -> Tag Text
forall a b. (a, b) -> a
fst) ((Tag Text -> Bool)
-> ParsecT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag Tag Text -> Bool
isCommentTag)
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Int
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar
) ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
rawListItem :: PandocMonad m
=> Bool
-> MarkdownParser m a
-> MarkdownParser m (Text, Int)
rawListItem :: forall (m :: * -> *) a.
PandocMonad m =>
Bool -> MarkdownParser m a -> MarkdownParser m (Text, Int)
rawListItem Bool
fourSpaceRule MarkdownParser m a
start = ParsecT Sources ParserState m (Text, Int)
-> ParsecT Sources ParserState m (Text, Int)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Text, Int)
-> ParsecT Sources ParserState m (Text, Int))
-> ParsecT Sources ParserState m (Text, Int)
-> ParsecT Sources ParserState m (Text, Int)
forall a b. (a -> b) -> a -> b
$ do
pos1 <- ParsecT Sources ParserState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
start
pos2 <- getPosition
let continuationIndent = if Bool
fourSpaceRule
then Int
4
else SourcePos -> Int
sourceColumn SourcePos
pos2 Int -> Int -> Int
forall a. Num a => a -> a -> a
- SourcePos -> Int
sourceColumn SourcePos
pos1
first <- listLineCommon
rest <- many (do notFollowedBy listStart
notFollowedBy (() <$ codeBlockFenced)
notFollowedBy blankline
listLine continuationIndent)
blanks <- manyChar blankline
let result = [Text] -> Text
T.unlines (Text
firstText -> [Text] -> [Text]
forall a. a -> [a] -> [a]
:[Text]
rest) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
blanks
return (result, continuationIndent)
listContinuation :: PandocMonad m => Int -> MarkdownParser m Text
listContinuation :: forall (m :: * -> *). PandocMonad m => Int -> MarkdownParser m Text
listContinuation Int
continuationIndent = ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ do
x <- ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ do
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
notFollowedByHtmlCloser
ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
notFollowedByDivCloser
Int -> ParsecT Sources ParserState m ()
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
Int -> ParsecT Sources st m ()
gobbleSpaces Int
continuationIndent
ParsecT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLineNewline
xs <- many $ try $ do
notFollowedBy blankline
notFollowedByHtmlCloser
notFollowedByDivCloser
gobbleSpaces continuationIndent <|> notFollowedBy' listStart
anyLineNewline
blanks <- manyChar blankline
return $ T.concat (x:xs) <> blanks
blanklines' :: PandocMonad m => MarkdownParser m Text
blanklines' :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
blanklines' = ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
blanklines ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Sources ParserState m Text
checkDivCloser
where checkDivCloser :: ParsecT Sources ParserState m Text
checkDivCloser = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_fenced_divs
divLevel <- ParserState -> Int
stateFencedDivLevel (ParserState -> Int)
-> ParsecT Sources ParserState m ParserState
-> ParsecT Sources ParserState m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
guard (divLevel >= 1)
lookAhead divFenceEnd
return ""
notFollowedByDivCloser :: PandocMonad m => MarkdownParser m ()
notFollowedByDivCloser :: forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
notFollowedByDivCloser =
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardDisabled Extension
Ext_fenced_divs ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
do divLevel <- ParserState -> Int
stateFencedDivLevel (ParserState -> Int)
-> ParsecT Sources ParserState m ParserState
-> ParsecT Sources ParserState m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
guard (divLevel < 1) <|> notFollowedBy divFenceEnd
notFollowedByHtmlCloser :: PandocMonad m => MarkdownParser m ()
notFollowedByHtmlCloser :: forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
notFollowedByHtmlCloser = do
inHtmlBlock <- ParserState -> Maybe Text
stateInHtmlBlock (ParserState -> Maybe Text)
-> ParsecT Sources ParserState m ParserState
-> ParsecT Sources ParserState m (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
case inHtmlBlock of
Just Text
t -> ParsecT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' (ParsecT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ (Tag Text -> Bool)
-> ParsecT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (Tag Text -> Tag Text -> Bool
forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== Text -> Tag Text
forall str. str -> Tag str
TagClose Text
t)
Maybe Text
Nothing -> () -> ParsecT Sources ParserState m ()
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
listItem :: PandocMonad m
=> Bool
-> MarkdownParser m a
-> MarkdownParser m (F Blocks)
listItem :: forall (m :: * -> *) a.
PandocMonad m =>
Bool
-> MarkdownParser m a
-> MarkdownParser m (Future ParserState Blocks)
listItem Bool
fourSpaceRule MarkdownParser m a
start = ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks))
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ do
state <- ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
let oldContext = ParserState -> ParserContext
stateParserContext ParserState
state
setState $ state {stateParserContext = ListItemState}
(first, continuationIndent) <- rawListItem fourSpaceRule start
continuations <- many (listContinuation continuationIndent)
let raw = [Text] -> Text
T.concat (Text
firstText -> [Text] -> [Text]
forall a. a -> [a] -> [a]
:[Text]
continuations)
contents <- parseFromString' parseBlocks raw
updateState (\ParserState
st -> ParserState
st {stateParserContext = oldContext})
exts <- getOption readerExtensions
return $ B.fromList . taskListItemFromAscii exts . B.toList <$> contents
orderedList :: PandocMonad m => MarkdownParser m (F Blocks)
orderedList :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
orderedList = ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks))
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ do
(start, style, delim) <- ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim)
-> ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (Maybe (ListNumberStyle, ListNumberDelim)
-> ParsecT
Sources ParserState m (Int, ListNumberStyle, ListNumberDelim)
forall (m :: * -> *).
PandocMonad m =>
Maybe (ListNumberStyle, ListNumberDelim)
-> MarkdownParser m (Int, ListNumberStyle, ListNumberDelim)
orderedListStart Maybe (ListNumberStyle, ListNumberDelim)
forall a. Maybe a
Nothing)
unless (style `elem` [DefaultStyle, Decimal, Example] &&
delim `elem` [DefaultDelim, Period]) $
guardEnabled Ext_fancy_lists
when (style == Example) $ guardEnabled Ext_example_lists
fourSpaceRule <- (True <$ guardEnabled Ext_four_space_rule)
<|> return (style == Example)
items <- fmap sequence $ many1 $ listItem fourSpaceRule
(orderedListStart (Just (style, delim)))
start' <- if style == Example
then return start
else (start <$ guardEnabled Ext_startnum) <|> return 1
return $ B.orderedListWith (start', style, delim) <$> fmap compactify items
bulletList :: PandocMonad m => MarkdownParser m (F Blocks)
bulletList :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
bulletList = do
fourSpaceRule <- (Bool
True Bool
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Bool
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_four_space_rule)
ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Bool -> ParsecT Sources ParserState m Bool
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
items <- fmap sequence $ many1 $ listItem fourSpaceRule bulletListStart
return $ B.bulletList <$> fmap compactify items
defListMarker :: PandocMonad m => MarkdownParser m ()
defListMarker :: forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
defListMarker = do
sps <- MarkdownParser m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
nonindentSpaces
char ':' <|> char '~'
tabStop <- getOption readerTabStop
let remaining = Int
tabStop Int -> Int -> Int
forall a. Num a => a -> a -> a
- (Text -> Int
T.length Text
sps Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
if remaining > 0
then try (count remaining (char ' ')) <|> string "\t" <|> many1 spaceChar
else mzero
return ()
definitionListItem :: PandocMonad m => Bool -> MarkdownParser m (F (Inlines, [Blocks]))
definitionListItem :: forall (m :: * -> *).
PandocMonad m =>
Bool -> MarkdownParser m (F (Inlines, [Blocks]))
definitionListItem Bool
compact = ParsecT Sources ParserState m (F (Inlines, [Blocks]))
-> ParsecT Sources ParserState m (F (Inlines, [Blocks]))
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F (Inlines, [Blocks]))
-> ParsecT Sources ParserState m (F (Inlines, [Blocks])))
-> ParsecT Sources ParserState m (F (Inlines, [Blocks]))
-> ParsecT Sources ParserState m (F (Inlines, [Blocks]))
forall a b. (a -> b) -> a -> b
$ do
rawLine' <- ParsecT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLine
raw <- many1 $ defRawBlock compact
term <- parseFromString' (trimInlinesF <$> inlines) rawLine'
contents <- mapM (parseFromString' parseBlocks . (<> "\n")) raw
optional blanklines
return $ liftM2 (,) term (sequence contents)
defRawBlock :: PandocMonad m => Bool -> MarkdownParser m Text
defRawBlock :: forall (m :: * -> *).
PandocMonad m =>
Bool -> MarkdownParser m Text
defRawBlock Bool
compact = ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ do
hasBlank <- Bool
-> ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False (ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool)
-> ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> ParsecT Sources ParserState m Bool
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
defListMarker
firstline <- anyLineNewline
let dline = ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try
( do ParsecT Sources ParserState m Char -> MarkdownParser m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
MarkdownParser m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
notFollowedByHtmlCloser
MarkdownParser m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
notFollowedByDivCloser
if Bool
compact
then () () -> ParsecT Sources ParserState m Text -> MarkdownParser m ()
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
indentSpaces
else (() () -> ParsecT Sources ParserState m Text -> MarkdownParser m ()
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
indentSpaces)
MarkdownParser m () -> MarkdownParser m () -> MarkdownParser m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MarkdownParser m () -> MarkdownParser m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy MarkdownParser m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
defListMarker
ParsecT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLine )
rawlines <- many dline
cont <- fmap T.concat $ many $ try $ do
trailing <- option "" blanklines
ln <- indentSpaces >> notFollowedBy blankline >> anyLine
lns <- many dline
return $ trailing <> T.unlines (ln:lns)
return $ trimr (firstline <> T.unlines rawlines <> cont) <>
if hasBlank || not (T.null cont) then "\n\n" else ""
definitionList :: PandocMonad m => MarkdownParser m (F Blocks)
definitionList :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
definitionList = ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks))
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ do
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLine ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
Control.Monad.void ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
table)) ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
defListMarker)
ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
compactDefinitionList ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
normalDefinitionList
compactDefinitionList :: PandocMonad m => MarkdownParser m (F Blocks)
compactDefinitionList :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
compactDefinitionList = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_compact_definition_lists
items <- ([F (Inlines, [Blocks])]
-> Future ParserState [(Inlines, [Blocks])])
-> ParsecT Sources ParserState m [F (Inlines, [Blocks])]
-> ParsecT
Sources ParserState m (Future ParserState [(Inlines, [Blocks])])
forall a b.
(a -> b)
-> ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [F (Inlines, [Blocks])] -> Future ParserState [(Inlines, [Blocks])]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence (ParsecT Sources ParserState m [F (Inlines, [Blocks])]
-> ParsecT
Sources ParserState m (Future ParserState [(Inlines, [Blocks])]))
-> ParsecT Sources ParserState m [F (Inlines, [Blocks])]
-> ParsecT
Sources ParserState m (Future ParserState [(Inlines, [Blocks])])
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m (F (Inlines, [Blocks]))
-> ParsecT Sources ParserState m [F (Inlines, [Blocks])]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Sources ParserState m (F (Inlines, [Blocks]))
-> ParsecT Sources ParserState m [F (Inlines, [Blocks])])
-> ParsecT Sources ParserState m (F (Inlines, [Blocks]))
-> ParsecT Sources ParserState m [F (Inlines, [Blocks])]
forall a b. (a -> b) -> a -> b
$ Bool -> ParsecT Sources ParserState m (F (Inlines, [Blocks]))
forall (m :: * -> *).
PandocMonad m =>
Bool -> MarkdownParser m (F (Inlines, [Blocks]))
definitionListItem Bool
True
return $ B.definitionList <$> fmap compactifyDL items
normalDefinitionList :: PandocMonad m => MarkdownParser m (F Blocks)
normalDefinitionList :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
normalDefinitionList = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_definition_lists
items <- ([F (Inlines, [Blocks])]
-> Future ParserState [(Inlines, [Blocks])])
-> ParsecT Sources ParserState m [F (Inlines, [Blocks])]
-> ParsecT
Sources ParserState m (Future ParserState [(Inlines, [Blocks])])
forall a b.
(a -> b)
-> ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [F (Inlines, [Blocks])] -> Future ParserState [(Inlines, [Blocks])]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence (ParsecT Sources ParserState m [F (Inlines, [Blocks])]
-> ParsecT
Sources ParserState m (Future ParserState [(Inlines, [Blocks])]))
-> ParsecT Sources ParserState m [F (Inlines, [Blocks])]
-> ParsecT
Sources ParserState m (Future ParserState [(Inlines, [Blocks])])
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m (F (Inlines, [Blocks]))
-> ParsecT Sources ParserState m [F (Inlines, [Blocks])]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Sources ParserState m (F (Inlines, [Blocks]))
-> ParsecT Sources ParserState m [F (Inlines, [Blocks])])
-> ParsecT Sources ParserState m (F (Inlines, [Blocks]))
-> ParsecT Sources ParserState m [F (Inlines, [Blocks])]
forall a b. (a -> b) -> a -> b
$ Bool -> ParsecT Sources ParserState m (F (Inlines, [Blocks]))
forall (m :: * -> *).
PandocMonad m =>
Bool -> MarkdownParser m (F (Inlines, [Blocks]))
definitionListItem Bool
False
return $ B.definitionList <$> items
para :: PandocMonad m => MarkdownParser m (F Blocks)
para :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
para = ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks))
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ do
exts <- (ReaderOptions -> Extensions)
-> ParsecT Sources ParserState m Extensions
forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParsecT s st m b
forall s (m :: * -> *) t b.
Stream s m t =>
(ReaderOptions -> b) -> ParsecT s ParserState m b
getOption ReaderOptions -> Extensions
readerExtensions
result <- trimInlinesF <$> inlines1
let figureOr Inlines -> Blocks
constr Inlines
inlns =
case Inlines -> [Inline]
forall a. Many a -> [a]
B.toList Inlines
inlns of
[Image Attr
attr [Inline]
figCaption (Text
src, Text
tit)]
| Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_implicit_figures Extensions
exts
, Bool -> Bool
not ([Inline] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Inline]
figCaption) -> do
Attr -> Inlines -> Text -> Text -> Blocks
implicitFigure Attr
attr ([Inline] -> Inlines
forall a. [a] -> Many a
B.fromList [Inline]
figCaption) Text
src Text
tit
[Inline]
_ -> Inlines -> Blocks
constr Inlines
inlns
option (figureOr B.plain <$> result)
$ try $ do
newline
(mempty <$ blanklines)
<|> (guardDisabled Ext_blank_before_blockquote
<* lookAhead blockQuote)
<|> (guardEnabled Ext_backtick_code_blocks
<* lookAhead codeBlockFenced)
<|> (guardDisabled Ext_blank_before_header
<* lookAhead header)
<|> (guardEnabled Ext_lists_without_preceding_blankline
<* notFollowedBy' inList
<* lookAhead listStart)
<|> do guardEnabled Ext_native_divs
inHtmlBlock <- stateInHtmlBlock <$> getState
case inHtmlBlock of
Just Text
"div" -> () ()
-> ParsecT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m ()
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$
ParsecT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m (Tag Text, Text)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ((Tag Text -> Bool)
-> ParsecT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (Tag Text -> Tag Text -> Bool
forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== Text -> Tag Text
forall str. str -> Tag str
TagClose (Text
"div" :: Text)))
Maybe Text
_ -> ParsecT Sources ParserState m ()
forall a. ParsecT Sources ParserState m a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
<|> do guardEnabled Ext_fenced_divs
divLevel <- stateFencedDivLevel <$> getState
if divLevel > 0
then lookAhead divFenceEnd
else mzero
return $ figureOr B.para <$> result
plain :: PandocMonad m => MarkdownParser m (F Blocks)
plain :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
plain = (Inlines -> Blocks) -> F Inlines -> Future ParserState Blocks
forall a b.
(a -> b) -> Future ParserState a -> Future ParserState b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Blocks
B.plain (F Inlines -> Future ParserState Blocks)
-> (F Inlines -> F Inlines)
-> F Inlines
-> Future ParserState Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> Future ParserState Blocks)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inlines1
implicitFigure :: Attr -> Inlines -> Text -> Text -> Blocks
implicitFigure :: Attr -> Inlines -> Text -> Text -> Blocks
implicitFigure (Text
ident, [Text]
classes, [Target]
attribs) Inlines
capt Text
url Text
title =
let alt :: Inlines
alt = case Text
"alt" Text -> [Target] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
`lookup` [Target]
attribs of
Just Text
alt' -> Text -> Inlines
B.text Text
alt'
Maybe Text
_ -> Inlines
capt
attribs' :: [Target]
attribs' = (Target -> Bool) -> [Target] -> [Target]
forall a. (a -> Bool) -> [a] -> [a]
filter ((Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"alt") (Text -> Bool) -> (Target -> Text) -> Target -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Target -> Text
forall a b. (a, b) -> a
fst) [Target]
attribs
figattr :: Attr
figattr = (Text
ident, [Text]
forall a. Monoid a => a
mempty, [Target]
forall a. Monoid a => a
mempty)
caption :: Caption
caption = Blocks -> Caption
B.simpleCaption (Blocks -> Caption) -> Blocks -> Caption
forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
B.plain Inlines
capt
figbody :: Blocks
figbody = Inlines -> Blocks
B.plain (Inlines -> Blocks) -> Inlines -> Blocks
forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Text -> Inlines -> Inlines
B.imageWith (Text
"", [Text]
classes, [Target]
attribs') Text
url Text
title Inlines
alt
in Attr -> Caption -> Blocks -> Blocks
B.figureWith Attr
figattr Caption
caption Blocks
figbody
htmlElement :: PandocMonad m => MarkdownParser m Text
htmlElement :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
htmlElement = MarkdownParser m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
rawVerbatimBlock
MarkdownParser m Text
-> MarkdownParser m Text -> MarkdownParser m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MarkdownParser m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
strictHtmlBlock
MarkdownParser m Text
-> MarkdownParser m Text -> MarkdownParser m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ((Tag Text, Text) -> Text)
-> ParsecT Sources ParserState m (Tag Text, Text)
-> MarkdownParser m Text
forall a b.
(a -> b)
-> ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Tag Text, Text) -> Text
forall a b. (a, b) -> b
snd ((Tag Text -> Bool)
-> ParsecT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag Tag Text -> Bool
isBlockTag)
htmlBlock :: PandocMonad m => MarkdownParser m (F Blocks)
htmlBlock :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
htmlBlock = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_raw_html
ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (do
(TagOpen _ attrs) <- ParsecT Sources ParserState m (Tag Text)
-> ParsecT Sources ParserState m (Tag Text)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Sources ParserState m (Tag Text)
-> ParsecT Sources ParserState m (Tag Text))
-> ParsecT Sources ParserState m (Tag Text)
-> ParsecT Sources ParserState m (Tag Text)
forall a b. (a -> b) -> a -> b
$ (Tag Text, Text) -> Tag Text
forall a b. (a, b) -> a
fst ((Tag Text, Text) -> Tag Text)
-> ParsecT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m (Tag Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Tag Text -> Bool)
-> ParsecT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag Tag Text -> Bool
isBlockTag
return . B.rawBlock "html" <$> rawVerbatimBlock
<|> (do guardEnabled Ext_markdown_attribute
oldMarkdownAttribute <- stateMarkdownAttribute <$> getState
markdownAttribute <-
case lookup "markdown" attrs of
Just Text
"0" -> Bool
False Bool
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Bool
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParserState -> ParserState) -> ParsecT Sources ParserState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState (\ParserState
st -> ParserState
st{
stateMarkdownAttribute = False })
Just Text
_ -> Bool
True Bool
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Bool
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParserState -> ParserState) -> ParsecT Sources ParserState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState (\ParserState
st -> ParserState
st{
stateMarkdownAttribute = True })
Maybe Text
Nothing -> Bool -> ParsecT Sources ParserState m Bool
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
oldMarkdownAttribute
res <- if markdownAttribute
then rawHtmlBlocks
else htmlBlock'
updateState $ \ParserState
st -> ParserState
st{ stateMarkdownAttribute =
oldMarkdownAttribute }
return res)
<|> (guardEnabled Ext_markdown_in_html_blocks >> rawHtmlBlocks))
ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
htmlBlock'
htmlBlock' :: PandocMonad m => MarkdownParser m (F Blocks)
htmlBlock' :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
htmlBlock' = ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks))
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ do
first <- MarkdownParser m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
htmlElement
skipMany spaceChar
optional blanklines
return $ if T.null first
then mempty
else return $ B.rawBlock "html" first
strictHtmlBlock :: PandocMonad m => MarkdownParser m Text
strictHtmlBlock :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
strictHtmlBlock = (Tag Text -> Bool) -> ParsecT Sources ParserState m Text
forall (m :: * -> *) st.
Monad m =>
(Tag Text -> Bool) -> ParsecT Sources st m Text
htmlInBalanced (Bool -> Bool
not (Bool -> Bool) -> (Tag Text -> Bool) -> Tag Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tag Text -> Bool
isInlineTag)
rawVerbatimBlock :: PandocMonad m => MarkdownParser m Text
rawVerbatimBlock :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
rawVerbatimBlock = (Tag Text -> Bool) -> ParsecT Sources ParserState m Text
forall (m :: * -> *) st.
Monad m =>
(Tag Text -> Bool) -> ParsecT Sources st m Text
htmlInBalanced Tag Text -> Bool
forall {a}. (Eq a, IsString a) => Tag a -> Bool
isVerbTag
where isVerbTag :: Tag a -> Bool
isVerbTag (TagOpen a
"pre" [Attribute a]
_) = Bool
True
isVerbTag (TagOpen a
"style" [Attribute a]
_) = Bool
True
isVerbTag (TagOpen a
"script" [Attribute a]
_) = Bool
True
isVerbTag (TagOpen a
"textarea" [Attribute a]
_) = Bool
True
isVerbTag Tag a
_ = Bool
False
rawTeXBlock :: PandocMonad m => MarkdownParser m (F Blocks)
rawTeXBlock :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
rawTeXBlock = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_raw_tex
result <- (Text -> Text -> Blocks
B.rawBlock Text
"tex" (Text -> Blocks) -> ([Text] -> Text) -> [Text] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
trim (Text -> Text) -> ([Text] -> Text) -> [Text] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Text
T.concat ([Text] -> Blocks)
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
(<>) (Text -> Text -> Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m (Text -> Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Text
forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m Text
rawConTeXtEnvironment ParsecT Sources ParserState m (Text -> Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b.
ParsecT Sources ParserState m (a -> b)
-> ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Sources ParserState m Text
forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m Text
spnl'))
ParsecT Sources ParserState m Blocks
-> ParsecT Sources ParserState m Blocks
-> ParsecT Sources ParserState m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Text -> Text -> Blocks
B.rawBlock Text
"tex" (Text -> Blocks) -> ([Text] -> Text) -> [Text] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
trim (Text -> Text) -> ([Text] -> Text) -> [Text] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Text
T.concat ([Text] -> Blocks)
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
(<>) (Text -> Text -> Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m (Text -> Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Text
forall (m :: * -> *) s.
(PandocMonad m, HasMacros s, HasReaderOptions s) =>
ParsecT Sources s m Text
rawLaTeXBlock ParsecT Sources ParserState m (Text -> Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b.
ParsecT Sources ParserState m (a -> b)
-> ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Sources ParserState m Text
forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m Text
spnl'))
return $ case B.toList result of
[RawBlock Format
_ Text
cs]
| (Char -> Bool) -> Text -> Bool
T.all (Char -> FilePath -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char
' ',Char
'\t',Char
'\n']) Text
cs -> Blocks -> Future ParserState Blocks
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty
[Block]
_ -> Blocks -> Future ParserState Blocks
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
result
rawHtmlBlocks :: PandocMonad m => MarkdownParser m (F Blocks)
rawHtmlBlocks :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
rawHtmlBlocks = do
(TagOpen tagtype _, raw) <- (Tag Text -> Bool)
-> ParsecT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag Tag Text -> Bool
isBlockTag
let selfClosing = Text
"/>" Text -> Text -> Bool
`T.isSuffixOf` Text
raw
skipMany spaceChar
tabStop <- getOption readerTabStop
indentlevel <- option 0 $
do blankline
sum <$> many ( (1 <$ char ' ')
<|>
(tabStop <$ char '\t') )
oldInHtmlBlock <- stateInHtmlBlock <$> getState
updateState $ \ParserState
st -> ParserState
st{ stateInHtmlBlock = Just tagtype }
let closer = (Tag Text -> Bool)
-> ParsecT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (Tag Text -> Tag Text -> Bool
forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== Text -> Tag Text
forall str. str -> Tag str
TagClose Text
tagtype)
let block' = ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks))
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ do
Int -> ParsecT Sources ParserState m Int
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
Int -> ParsecT Sources st m Int
gobbleAtMostSpaces Int
indentlevel
ParsecT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' ParsecT Sources ParserState m (Tag Text, Text)
closer
ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
block
contents <- if selfClosing
then return mempty
else mconcat <$> many block'
result <-
try
(do gobbleAtMostSpaces indentlevel
(_, rawcloser) <- closer
return (return (B.rawBlock "html" $ stripMarkdownAttribute raw) <>
contents <>
return (B.rawBlock "html" rawcloser)))
<|> return (return (B.rawBlock "html" raw) <> contents)
updateState $ \ParserState
st -> ParserState
st{ stateInHtmlBlock = oldInHtmlBlock }
return result
stripMarkdownAttribute :: Text -> Text
stripMarkdownAttribute :: Text -> Text
stripMarkdownAttribute Text
s = [Tag Text] -> Text
renderTags' ([Tag Text] -> Text) -> [Tag Text] -> Text
forall a b. (a -> b) -> a -> b
$ (Tag Text -> Tag Text) -> [Tag Text] -> [Tag Text]
forall a b. (a -> b) -> [a] -> [b]
map Tag Text -> Tag Text
forall {a}. (Eq a, IsString a) => Tag a -> Tag a
filterAttrib ([Tag Text] -> [Tag Text]) -> [Tag Text] -> [Tag Text]
forall a b. (a -> b) -> a -> b
$ Text -> [Tag Text]
forall str. StringLike str => str -> [Tag str]
parseTags Text
s
where filterAttrib :: Tag a -> Tag a
filterAttrib (TagOpen a
t [Attribute a]
as) = a -> [Attribute a] -> Tag a
forall str. str -> [Attribute str] -> Tag str
TagOpen a
t
[(a
k,a
v) | (a
k,a
v) <- [Attribute a]
as, a
k a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
"markdown"]
filterAttrib Tag a
x = Tag a
x
lineBlock :: PandocMonad m => MarkdownParser m (F Blocks)
lineBlock :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
lineBlock = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_line_blocks
ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks))
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ do
lines' <- ParsecT Sources ParserState m [Text]
forall (m :: * -> *) st. Monad m => ParsecT Sources st m [Text]
lineBlockLines ParsecT Sources ParserState m [Text]
-> ([Text] -> ParsecT Sources ParserState m [F Inlines])
-> ParsecT Sources ParserState m [F Inlines]
forall a b.
ParsecT Sources ParserState m a
-> (a -> ParsecT Sources ParserState m b)
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(Text -> ParsecT Sources ParserState m (F Inlines))
-> [Text] -> ParsecT Sources ParserState m [F Inlines]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (ParsecT Sources ParserState m (F Inlines)
-> Text -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParsecT Sources u m a -> Text -> ParsecT Sources u m a
parseFromString' (F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inlines))
return $ B.lineBlock <$> sequence lines'
dashedLine :: PandocMonad m
=> Char
-> ParsecT Sources st m (Int, Int)
dashedLine :: forall (m :: * -> *) st.
PandocMonad m =>
Char -> ParsecT Sources st m (Int, Int)
dashedLine Char
ch = do
dashes <- ParsecT Sources st m Char -> ParsecT Sources st m FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (Char -> ParsecT Sources st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
ch)
sp <- many spaceChar
let lengthDashes = FilePath -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length FilePath
dashes
lengthSp = FilePath -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length FilePath
sp
return (lengthDashes, lengthDashes + lengthSp)
simpleTableHeader :: PandocMonad m
=> Bool
-> MarkdownParser m (F [Blocks], [Alignment], [Int])
Bool
headless = ParsecT
Sources
ParserState
m
(Future ParserState [Blocks], [Alignment], [Int])
-> ParsecT
Sources
ParserState
m
(Future ParserState [Blocks], [Alignment], [Int])
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT
Sources
ParserState
m
(Future ParserState [Blocks], [Alignment], [Int])
-> ParsecT
Sources
ParserState
m
(Future ParserState [Blocks], [Alignment], [Int]))
-> ParsecT
Sources
ParserState
m
(Future ParserState [Blocks], [Alignment], [Int])
-> ParsecT
Sources
ParserState
m
(Future ParserState [Blocks], [Alignment], [Int])
forall a b. (a -> b) -> a -> b
$ do
rawContent <- if Bool
headless
then Text -> ParsecT Sources ParserState m Text
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
""
else ParsecT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLine
initSp <- nonindentSpaces
dashes <- many1 (dashedLine '-')
newline
let (lengths, lines') = unzip dashes
let indices = (Int -> Int -> Int) -> Int -> [Int] -> [Int]
forall b a. (b -> a -> b) -> b -> [a] -> [b]
scanl Int -> Int -> Int
forall a. Num a => a -> a -> a
(+) (Text -> Int
T.length Text
initSp) [Int]
lines'
rawHeads <- fmap (drop 1 . splitTextByIndices (init indices)) $
if headless
then lookAhead anyLine
else return rawContent
let aligns = ([Text] -> Int -> Alignment) -> [[Text]] -> [Int] -> [Alignment]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith [Text] -> Int -> Alignment
alignType ((Text -> [Text]) -> [Text] -> [[Text]]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: []) [Text]
rawHeads) [Int]
lengths
let rawHeads' = if Bool
headless
then []
else [Text]
rawHeads
heads <- fmap sequence
$
mapM (parseFromString' (mconcat <$> many plain).trim) rawHeads'
return (heads, aligns, indices)
alignType :: [Text]
-> Int
-> Alignment
alignType :: [Text] -> Int -> Alignment
alignType [] Int
_ = Alignment
AlignDefault
alignType [Text]
strLst Int
len =
let nonempties :: [Text]
nonempties = (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Text -> Bool) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Bool
T.null) ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ (Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Text
trimr [Text]
strLst
(Bool
leftSpace, Bool
rightSpace) =
case (Text -> Int) -> [Text] -> [Text]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn Text -> Int
T.length [Text]
nonempties of
(Text
x:[Text]
_) -> (HasCallStack => Text -> Char
Text -> Char
T.head Text
x Char -> FilePath -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char
' ', Char
'\t'], Text -> Int
T.length Text
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
len)
[] -> (Bool
False, Bool
False)
in case (Bool
leftSpace, Bool
rightSpace) of
(Bool
True, Bool
False) -> Alignment
AlignRight
(Bool
False, Bool
True) -> Alignment
AlignLeft
(Bool
True, Bool
True) -> Alignment
AlignCenter
(Bool
False, Bool
False) -> Alignment
AlignDefault
tableFooter :: PandocMonad m => MarkdownParser m Text
= ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ MarkdownParser m Int
forall (m :: * -> *). PandocMonad m => MarkdownParser m Int
skipNonindentSpaces MarkdownParser m Int
-> ParsecT Sources ParserState m [(Int, Int)]
-> ParsecT Sources ParserState m [(Int, Int)]
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m (Int, Int)
-> ParsecT Sources ParserState m [(Int, Int)]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (Char -> ParsecT Sources ParserState m (Int, Int)
forall (m :: * -> *) st.
PandocMonad m =>
Char -> ParsecT Sources st m (Int, Int)
dashedLine Char
'-') ParsecT Sources ParserState m [(Int, Int)]
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
blanklines'
tableSep :: PandocMonad m => MarkdownParser m Char
tableSep :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Char
tableSep = ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b. (a -> b) -> a -> b
$ MarkdownParser m Int
forall (m :: * -> *). PandocMonad m => MarkdownParser m Int
skipNonindentSpaces MarkdownParser m Int
-> ParsecT Sources ParserState m [(Int, Int)]
-> ParsecT Sources ParserState m [(Int, Int)]
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m (Int, Int)
-> ParsecT Sources ParserState m [(Int, Int)]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (Char -> ParsecT Sources ParserState m (Int, Int)
forall (m :: * -> *) st.
PandocMonad m =>
Char -> ParsecT Sources st m (Int, Int)
dashedLine Char
'-') ParsecT Sources ParserState m [(Int, Int)]
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\n'
rawTableLine :: PandocMonad m
=> [Int]
-> MarkdownParser m [Text]
rawTableLine :: forall (m :: * -> *).
PandocMonad m =>
[Int] -> MarkdownParser m [Text]
rawTableLine [Int]
indices = do
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' (ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
blanklines' ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
tableFooter)
line <- ParsecT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLine
return $ map trim $ drop 1 $ splitTextByIndices (init indices) line
tableLine :: PandocMonad m
=> [Int]
-> MarkdownParser m (F [Blocks])
tableLine :: forall (m :: * -> *).
PandocMonad m =>
[Int] -> MarkdownParser m (Future ParserState [Blocks])
tableLine [Int]
indices = [Int] -> MarkdownParser m [Text]
forall (m :: * -> *).
PandocMonad m =>
[Int] -> MarkdownParser m [Text]
rawTableLine [Int]
indices MarkdownParser m [Text]
-> ([Text]
-> ParsecT Sources ParserState m (Future ParserState [Blocks]))
-> ParsecT Sources ParserState m (Future ParserState [Blocks])
forall a b.
ParsecT Sources ParserState m a
-> (a -> ParsecT Sources ParserState m b)
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
([Future ParserState Blocks] -> Future ParserState [Blocks])
-> ParsecT Sources ParserState m [Future ParserState Blocks]
-> ParsecT Sources ParserState m (Future ParserState [Blocks])
forall a b.
(a -> b)
-> ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Future ParserState Blocks] -> Future ParserState [Blocks]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence (ParsecT Sources ParserState m [Future ParserState Blocks]
-> ParsecT Sources ParserState m (Future ParserState [Blocks]))
-> ([Text]
-> ParsecT Sources ParserState m [Future ParserState Blocks])
-> [Text]
-> ParsecT Sources ParserState m (Future ParserState [Blocks])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> ParsecT Sources ParserState m (Future ParserState Blocks))
-> [Text]
-> ParsecT Sources ParserState m [Future ParserState Blocks]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (ParsecT Sources ParserState m (Future ParserState Blocks)
-> Text
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParsecT Sources u m a -> Text -> ParsecT Sources u m a
parseFromString' ([Future ParserState Blocks] -> Future ParserState Blocks
forall a. Monoid a => [a] -> a
mconcat ([Future ParserState Blocks] -> Future ParserState Blocks)
-> ParsecT Sources ParserState m [Future ParserState Blocks]
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m [Future ParserState Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
plain))
multilineRow :: PandocMonad m
=> [Int]
-> MarkdownParser m (F [Blocks])
multilineRow :: forall (m :: * -> *).
PandocMonad m =>
[Int] -> MarkdownParser m (Future ParserState [Blocks])
multilineRow [Int]
indices = do
colLines <- ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m [[Text]]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ([Int] -> ParsecT Sources ParserState m [Text]
forall (m :: * -> *).
PandocMonad m =>
[Int] -> MarkdownParser m [Text]
rawTableLine [Int]
indices)
let cols = ([Text] -> Text) -> [[Text]] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map [Text] -> Text
T.unlines ([[Text]] -> [Text]) -> [[Text]] -> [Text]
forall a b. (a -> b) -> a -> b
$ [[Text]] -> [[Text]]
forall a. [[a]] -> [[a]]
transpose [[Text]]
colLines
fmap sequence $ mapM (parseFromString' (mconcat <$> many plain)) cols
tableCaption :: PandocMonad m => MarkdownParser m (F Inlines)
tableCaption :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
tableCaption = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_table_captions
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
MarkdownParser m Int
forall (m :: * -> *). PandocMonad m => MarkdownParser m Int
skipNonindentSpaces
(FilePath -> ParsecT Sources ParserState m 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 m FilePath
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m FilePath
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ((Char -> Bool) -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isPunctuation)) ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m FilePath
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
(FilePath -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
oneOf [Char
'T',Char
't'] ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m FilePath
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FilePath -> ParsecT Sources ParserState m FilePath
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m FilePath
string FilePath
"able:")
F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inlines1 ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
blanklines
simpleTable :: PandocMonad m
=> Bool
-> MarkdownParser m (F TableComponents)
simpleTable :: forall (m :: * -> *).
PandocMonad m =>
Bool -> MarkdownParser m (F TableComponents)
simpleTable Bool
headless = do
tableComponents <-
TableNormalization
-> ParsecT
Sources
ParserState
m
(Future ParserState [Blocks], [Alignment], [Int])
-> ([Int]
-> ParsecT Sources ParserState m (Future ParserState [Blocks]))
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m (F TableComponents)
forall s (m :: * -> *) st (mf :: * -> *) sep end.
(Stream s m Char, UpdateSourcePos s Char, HasReaderOptions st,
Monad mf) =>
TableNormalization
-> ParsecT s st m (mf [Blocks], [Alignment], [Int])
-> ([Int] -> ParsecT s st m (mf [Blocks]))
-> ParsecT s st m sep
-> ParsecT s st m end
-> ParsecT s st m (mf TableComponents)
tableWith' TableNormalization
NormalizeHeader
(Bool
-> ParsecT
Sources
ParserState
m
(Future ParserState [Blocks], [Alignment], [Int])
forall (m :: * -> *).
PandocMonad m =>
Bool
-> MarkdownParser
m (Future ParserState [Blocks], [Alignment], [Int])
simpleTableHeader Bool
headless) [Int]
-> ParsecT Sources ParserState m (Future ParserState [Blocks])
forall (m :: * -> *).
PandocMonad m =>
[Int] -> MarkdownParser m (Future ParserState [Blocks])
tableLine
(() -> ParsecT Sources ParserState m ()
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return ())
(if Bool
headless then ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
tableFooter else ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
tableFooter ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
blanklines')
let useDefaultColumnWidths TableComponents
tc =
let cs' :: [(Alignment, ColWidth)]
cs' = ((Alignment, ColWidth) -> (Alignment, ColWidth))
-> [(Alignment, ColWidth)] -> [(Alignment, ColWidth)]
forall a b. (a -> b) -> [a] -> [b]
map ((ColWidth -> ColWidth)
-> (Alignment, ColWidth) -> (Alignment, ColWidth)
forall b c a. (b -> c) -> (a, b) -> (a, c)
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second (ColWidth -> ColWidth -> ColWidth
forall a b. a -> b -> a
const ColWidth
ColWidthDefault)) ([(Alignment, ColWidth)] -> [(Alignment, ColWidth)])
-> [(Alignment, ColWidth)] -> [(Alignment, ColWidth)]
forall a b. (a -> b) -> a -> b
$ TableComponents -> [(Alignment, ColWidth)]
tableColSpecs TableComponents
tc
in TableComponents
tc {tableColSpecs = cs'}
return $ useDefaultColumnWidths <$> tableComponents
multilineTable :: PandocMonad m
=> Bool
-> MarkdownParser m (F TableComponents)
multilineTable :: forall (m :: * -> *).
PandocMonad m =>
Bool -> MarkdownParser m (F TableComponents)
multilineTable Bool
headless =
TableNormalization
-> ParsecT
Sources
ParserState
m
(Future ParserState [Blocks], [Alignment], [Int])
-> ([Int]
-> ParsecT Sources ParserState m (Future ParserState [Blocks]))
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m (F TableComponents)
forall s (m :: * -> *) st (mf :: * -> *) sep end.
(Stream s m Char, UpdateSourcePos s Char, HasReaderOptions st,
Monad mf) =>
TableNormalization
-> ParsecT s st m (mf [Blocks], [Alignment], [Int])
-> ([Int] -> ParsecT s st m (mf [Blocks]))
-> ParsecT s st m sep
-> ParsecT s st m end
-> ParsecT s st m (mf TableComponents)
tableWith' TableNormalization
NormalizeHeader (Bool
-> ParsecT
Sources
ParserState
m
(Future ParserState [Blocks], [Alignment], [Int])
forall (m :: * -> *).
PandocMonad m =>
Bool
-> MarkdownParser
m (Future ParserState [Blocks], [Alignment], [Int])
multilineTableHeader Bool
headless)
[Int]
-> ParsecT Sources ParserState m (Future ParserState [Blocks])
forall (m :: * -> *).
PandocMonad m =>
[Int] -> MarkdownParser m (Future ParserState [Blocks])
multilineRow ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
blanklines ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
tableFooter
multilineTableHeader :: PandocMonad m
=> Bool
-> MarkdownParser m (F [Blocks], [Alignment], [Int])
Bool
headless = ParsecT
Sources
ParserState
m
(Future ParserState [Blocks], [Alignment], [Int])
-> ParsecT
Sources
ParserState
m
(Future ParserState [Blocks], [Alignment], [Int])
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT
Sources
ParserState
m
(Future ParserState [Blocks], [Alignment], [Int])
-> ParsecT
Sources
ParserState
m
(Future ParserState [Blocks], [Alignment], [Int]))
-> ParsecT
Sources
ParserState
m
(Future ParserState [Blocks], [Alignment], [Int])
-> ParsecT
Sources
ParserState
m
(Future ParserState [Blocks], [Alignment], [Int])
forall a b. (a -> b) -> a -> b
$ do
Bool
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
headless (ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$
MarkdownParser m Char
forall (m :: * -> *). PandocMonad m => MarkdownParser m Char
tableSep MarkdownParser m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> MarkdownParser m Char -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy MarkdownParser m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
rawContent <- if Bool
headless
then [Text] -> ParsecT Sources ParserState m [Text]
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Text] -> ParsecT Sources ParserState m [Text])
-> [Text] -> ParsecT Sources ParserState m [Text]
forall a b. (a -> b) -> a -> b
$ Text -> [Text]
forall a. a -> [a]
repeat Text
""
else ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text])
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall a b. (a -> b) -> a -> b
$ MarkdownParser m Char -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy MarkdownParser m Char
forall (m :: * -> *). PandocMonad m => MarkdownParser m Char
tableSep ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLine
initSp <- nonindentSpaces
dashes <- many1 (dashedLine '-')
newline
let (lengths, lines') = unzip dashes
let indices = (Int -> Int -> Int) -> Int -> [Int] -> [Int]
forall b a. (b -> a -> b) -> b -> [a] -> [b]
scanl Int -> Int -> Int
forall a. Num a => a -> a -> a
(+) (Text -> Int
T.length Text
initSp) [Int]
lines'
let indices' = case [Int] -> [Int]
forall a. [a] -> [a]
reverse [Int]
indices of
[] -> []
(Int
x:[Int]
xs) -> [Int] -> [Int]
forall a. [a] -> [a]
reverse (Int
xInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:[Int]
xs)
rawHeadsList <- if headless
then map (:[]) . drop 1 . splitTextByIndices (init indices')
<$> lookAhead anyLine
else return $ transpose $ map
(drop 1 . splitTextByIndices (init indices'))
rawContent
let aligns = ([Text] -> Int -> Alignment) -> [[Text]] -> [Int] -> [Alignment]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith [Text] -> Int -> Alignment
alignType [[Text]]
rawHeadsList [Int]
lengths
let rawHeads = if Bool
headless
then []
else ([Text] -> Text) -> [[Text]] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map ([Text] -> Text
T.unlines ([Text] -> Text) -> ([Text] -> [Text]) -> [Text] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Text
trim) [[Text]]
rawHeadsList
heads <- fmap sequence $
mapM (parseFromString' (mconcat <$> many plain).trim) rawHeads
return (heads, aligns, indices')
gridTable :: PandocMonad m
=> MarkdownParser m (F TableComponents)
gridTable :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (F TableComponents)
gridTable = TableNormalization
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (F TableComponents)
forall (m :: * -> *) (mf :: * -> *) st.
(Monad m, Monad mf, HasReaderOptions st, HasLastStrPosition st) =>
TableNormalization
-> ParsecT Sources st m (mf Blocks)
-> ParsecT Sources st m (mf TableComponents)
gridTableWith' TableNormalization
NormalizeHeader ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
parseBlocks
pipeBreak :: PandocMonad m => MarkdownParser m ([Alignment], [Int])
pipeBreak :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m ([Alignment], [Int])
pipeBreak = ParsecT Sources ParserState m ([Alignment], [Int])
-> ParsecT Sources ParserState m ([Alignment], [Int])
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m ([Alignment], [Int])
-> ParsecT Sources ParserState m ([Alignment], [Int]))
-> ParsecT Sources ParserState m ([Alignment], [Int])
-> ParsecT Sources ParserState m ([Alignment], [Int])
forall a b. (a -> b) -> a -> b
$ do
MarkdownParser m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
nonindentSpaces
openPipe <- (Bool
True Bool
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Bool
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|') ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Bool -> ParsecT Sources ParserState m Bool
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
first <- pipeTableHeaderPart
rest <- many $ sepPipe *> pipeTableHeaderPart
closePipe <- (True <$ char '|') <|> return False
guard $ not (null rest && not (openPipe || closePipe))
blankline
return $ unzip (first:rest)
pipeTable :: PandocMonad m => MarkdownParser m (F TableComponents)
pipeTable :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (F TableComponents)
pipeTable = ParsecT Sources ParserState m (F TableComponents)
-> ParsecT Sources ParserState m (F TableComponents)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F TableComponents)
-> ParsecT Sources ParserState m (F TableComponents))
-> ParsecT Sources ParserState m (F TableComponents)
-> ParsecT Sources ParserState m (F TableComponents)
forall a b. (a -> b) -> a -> b
$ do
MarkdownParser m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
nonindentSpaces
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
nonspaceChar
(heads,(aligns, seplengths)) <- (,) ([Text] -> ([Alignment], [Int]) -> ([Text], ([Alignment], [Int])))
-> ParsecT Sources ParserState m [Text]
-> ParsecT
Sources
ParserState
m
(([Alignment], [Int]) -> ([Text], ([Alignment], [Int])))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m [Text]
forall (m :: * -> *). PandocMonad m => MarkdownParser m [Text]
pipeTableRow ParsecT
Sources
ParserState
m
(([Alignment], [Int]) -> ([Text], ([Alignment], [Int])))
-> ParsecT Sources ParserState m ([Alignment], [Int])
-> ParsecT Sources ParserState m ([Text], ([Alignment], [Int]))
forall a b.
ParsecT Sources ParserState m (a -> b)
-> ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Sources ParserState m ([Alignment], [Int])
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m ([Alignment], [Int])
pipeBreak
let cellContents = ParsecT Sources ParserState m (Future ParserState Blocks)
-> Text
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParsecT Sources u m a -> Text -> ParsecT Sources u m a
parseFromString' ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
pipeTableCell (Text -> ParsecT Sources ParserState m (Future ParserState Blocks))
-> (Text -> Text)
-> Text
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
trim
let numcols = [Alignment] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Alignment]
aligns
let heads' = Int -> [Text] -> [Text]
forall a. Int -> [a] -> [a]
take Int
numcols [Text]
heads
lines' <- many pipeTableRow
let lines'' = ([Text] -> [Text]) -> [[Text]] -> [[Text]]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> [Text] -> [Text]
forall a. Int -> [a] -> [a]
take Int
numcols) [[Text]]
lines'
let lineWidths = ([Text] -> Int) -> [[Text]] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map ([Int] -> Int
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([Int] -> Int) -> ([Text] -> [Int]) -> [Text] -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Int) -> [Text] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Int
forall a. HasChars a => a -> Int
realLength) ([Text]
heads' [Text] -> [[Text]] -> [[Text]]
forall a. a -> [a] -> [a]
: [[Text]]
lines'')
columns <- getOption readerColumns
let widths = if [Int] -> Int
forall (f :: * -> *) a. (Foldable f, Ord a, Bounded a) => f a -> a
maximumBounded ([Int] -> Int
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum [Int]
seplengths Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
: [Int]
lineWidths) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int
numcols Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
columns
then (Int -> Double) -> [Int] -> [Double]
forall a b. (a -> b) -> [a] -> [b]
map (\Int
len ->
Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
len Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([Int] -> Int
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum [Int]
seplengths))
[Int]
seplengths
else Int -> Double -> [Double]
forall a. Int -> a -> [a]
replicate ([Alignment] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Alignment]
aligns) Double
0.0
(headCells :: F [Blocks]) <- sequence <$> mapM cellContents heads'
(rows :: F [[Blocks]]) <- sequence <$>
mapM (fmap sequence . mapM cellContents) lines''
return $
toTableComponents' NormalizeHeader aligns widths <$> headCells <*> rows
sepPipe :: PandocMonad m => MarkdownParser m ()
sepPipe :: forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
sepPipe = ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'+'
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
pipeTableRow :: PandocMonad m => MarkdownParser m [Text]
pipeTableRow :: forall (m :: * -> *). PandocMonad m => MarkdownParser m [Text]
pipeTableRow = ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m [Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m [Text])
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m [Text]
forall a b. (a -> b) -> a -> b
$ do
ParsecT Sources ParserState m ()
forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m ()
scanForPipe
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
openPipe <- (Bool
True Bool
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Bool
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|') ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Bool -> ParsecT Sources ParserState m Bool
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
let chunk = ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
code ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
math ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
rawHtmlInline ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
escapedChar ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
rawLaTeXInline')
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (FilePath -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
noneOf FilePath
"|\n\r")
cells <- (snd <$> withRaw (many chunk)) `sepBy1` char '|'
closePipe <- (True <$ char '|') <|> return False
guard $ not (length cells == 1 && not (openPipe || closePipe))
blankline
return cells
pipeTableCell :: PandocMonad m => MarkdownParser m (F Blocks)
pipeTableCell :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
pipeTableCell =
(do result <- MarkdownParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inlines1
return $ B.plain <$> result)
ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Future ParserState Blocks
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Future ParserState Blocks
forall a. Monoid a => a
mempty
pipeTableHeaderPart :: PandocMonad m => ParsecT Sources st m (Alignment, Int)
= ParsecT Sources st m (Alignment, Int)
-> ParsecT Sources st m (Alignment, Int)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources st m (Alignment, Int)
-> ParsecT Sources st m (Alignment, Int))
-> ParsecT Sources st m (Alignment, Int)
-> ParsecT Sources st m (Alignment, Int)
forall a b. (a -> b) -> a -> b
$ do
ParsecT Sources st m Char -> ParsecT Sources st m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources st m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
left <- ParsecT Sources st m Char -> ParsecT Sources st m (Maybe Char)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (Char -> ParsecT Sources st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
':')
pipe <- many1 (char '-')
right <- optionMaybe (char ':')
skipMany spaceChar
let len = FilePath -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length FilePath
pipe Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int -> (Char -> Int) -> Maybe Char -> Int
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
0 (Int -> Char -> Int
forall a b. a -> b -> a
const Int
1) Maybe Char
left Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int -> (Char -> Int) -> Maybe Char -> Int
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
0 (Int -> Char -> Int
forall a b. a -> b -> a
const Int
1) Maybe Char
right
return
(case (left,right) of
(Maybe Char
Nothing,Maybe Char
Nothing) -> Alignment
AlignDefault
(Just Char
_,Maybe Char
Nothing) -> Alignment
AlignLeft
(Maybe Char
Nothing,Just Char
_) -> Alignment
AlignRight
(Just Char
_,Just Char
_) -> Alignment
AlignCenter, len)
scanForPipe :: PandocMonad m => ParsecT Sources st m ()
scanForPipe :: forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m ()
scanForPipe = do
Sources inps <- ParsecT Sources st m Sources
forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput
let ln = case [(SourcePos, Text)]
inps of
[] -> Text
""
((SourcePos
_,Text
t):(SourcePos
_,Text
t'):[(SourcePos, Text)]
_) | Text -> Bool
T.null Text
t -> Text
t'
((SourcePos
_,Text
t):[(SourcePos, Text)]
_) -> Text
t
case T.break (\Char
c -> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\n' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'|') ln of
(Text
_, Text -> Maybe (Char, Text)
T.uncons -> Just (Char
'|', Text
_)) -> () -> ParsecT Sources st m ()
forall a. a -> ParsecT Sources st m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Target
_ -> ParsecT Sources st m ()
forall a. ParsecT Sources st m a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
table :: PandocMonad m => MarkdownParser m (F Blocks)
table :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
table = ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks))
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ do
frontCaption <- Maybe (F Inlines)
-> ParsecT Sources ParserState m (Maybe (F Inlines))
-> ParsecT Sources ParserState m (Maybe (F Inlines))
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Maybe (F Inlines)
forall a. Maybe a
Nothing (F Inlines -> Maybe (F Inlines)
forall a. a -> Maybe a
Just (F Inlines -> Maybe (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (Maybe (F Inlines))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
tableCaption)
tableComponents <-
(guardEnabled Ext_pipe_tables >> try (scanForPipe >> pipeTable)) <|>
(guardEnabled Ext_multiline_tables >> try (multilineTable False)) <|>
(guardEnabled Ext_simple_tables >>
try (simpleTable True <|> simpleTable False)) <|>
(guardEnabled Ext_multiline_tables >>
try (multilineTable True)) <|>
(guardEnabled Ext_grid_tables >>
try gridTable) <?> "table"
optional blanklines
caption <- case frontCaption of
Maybe (F Inlines)
Nothing -> F Inlines
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty) ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
tableCaption
Just F Inlines
c -> F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return F Inlines
c
return $ do
caption' <- caption
(TableComponents _attr _capt colspecs th tb tf) <- tableComponents
return $ B.table (B.simpleCaption $ B.plain caption') colspecs th tb tf
inlines :: PandocMonad m => MarkdownParser m (F Inlines)
inlines :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inlines = [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inline
inlines1 :: PandocMonad m => MarkdownParser m (F Inlines)
inlines1 :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inlines1 = [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inline
inline :: PandocMonad m => MarkdownParser m (F Inlines)
inline :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inline = do
c <- ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar
((case c of
Char
' ' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
whitespace
Char
'\t' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
whitespace
Char
'\n' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
endline
Char
'`' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
code
Char
'_' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
strongOrEmph
Char
'*' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
strongOrEmph
Char
'^' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
superscript ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inlineNote
Char
'[' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
note ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
cite ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
bracketedSpan ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Attr -> Text -> Text -> Inlines -> Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
(Attr -> Text -> Text -> Inlines -> Inlines)
-> MarkdownParser m (F Inlines)
wikilink Attr -> Text -> Text -> Inlines -> Inlines
B.linkWith ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
link
Char
'!' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
image
Char
'$' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
math
Char
'~' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
strikeout ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
subscript
Char
'=' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
mark
Char
'<' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
autoLink ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
spanHtml ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
rawHtmlInline ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
ltSign
Char
'\\' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
math ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
escapedNewline ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
escapedChar ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
rawLaTeXInline'
Char
'@' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
cite ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
exampleRef
Char
'"' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
smart
Char
'\'' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
smart
Char
'\8216' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
smart
Char
'\145' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
smart
Char
'\8220' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
smart
Char
'\147' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
smart
Char
'-' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
cite ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
smart
Char
'.' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
smart
Char
'&' -> Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines)
-> (Inline -> Inlines) -> Inline -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inline -> Inlines
forall a. a -> Many a
B.singleton (Inline -> F Inlines)
-> ParsecT Sources ParserState m Inline
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Inline
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Inline
charRef
Char
':' -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
emoji
Char
_ -> ParsecT Sources ParserState m (F Inlines)
forall a. ParsecT Sources ParserState m a
forall (m :: * -> *) a. MonadPlus m => m a
mzero)
<|> bareURL
<|> str
<|> symbol) <?> "inline"
escapedChar' :: PandocMonad m => MarkdownParser m Char
escapedChar' :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Char
escapedChar' = ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\\'
(Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_all_symbols_escapable ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (Char -> Bool) -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
isAlphaNum))
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_angle_brackets_escapable ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
FilePath -> ParsecT Sources ParserState m 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 m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> FilePath -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
oneOf FilePath
"\\`*_{}[]()>#+-.!"
escapedNewline :: PandocMonad m => MarkdownParser m (F Inlines)
escapedNewline :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
escapedNewline = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_escaped_line_breaks
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\\'
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\n')
F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> ParsecT Sources ParserState m (F Inlines))
-> F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.linebreak
escapedChar :: PandocMonad m => MarkdownParser m (F Inlines)
escapedChar :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
escapedChar = do
result <- MarkdownParser m Char
forall (m :: * -> *). PandocMonad m => MarkdownParser m Char
escapedChar'
case result of
Char
' ' -> F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> ParsecT Sources ParserState m (F Inlines))
-> F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
"\160"
Char
_ -> F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> ParsecT Sources ParserState m (F Inlines))
-> F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ Char -> Text
T.singleton Char
result
ltSign :: PandocMonad m => MarkdownParser m (F Inlines)
ltSign :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
ltSign = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardDisabled Extension
Ext_raw_html
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
notFollowedByHtmlCloser ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' ((Tag Text -> Bool)
-> ParsecT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag Tag Text -> Bool
isBlockTag))
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'<'
F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> ParsecT Sources ParserState m (F Inlines))
-> F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
"<"
exampleRef :: PandocMonad m => MarkdownParser m (F Inlines)
exampleRef :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
exampleRef = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_example_lists
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'@'
lab <- [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat ([Text] -> Text) -> ([FilePath] -> [Text]) -> [FilePath] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FilePath -> Text) -> [FilePath] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map FilePath -> Text
T.pack ([FilePath] -> Text)
-> ParsecT Sources ParserState m [FilePath]
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m [FilePath]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m FilePath
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (do c <- Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'_' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'-'
cs <- many1 alphaNum
return (c:cs)))
return $ do
st <- askF
return $ case M.lookup lab (stateExamples st) of
Just Int
n -> Text -> Inlines
B.str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ Int -> Text
forall a. Show a => a -> Text
tshow Int
n
Maybe Int
Nothing -> Text -> Inlines
B.str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ Text
"@" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
lab
symbol :: PandocMonad m => MarkdownParser m (F Inlines)
symbol :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
symbol = do
result <- FilePath -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
noneOf FilePath
"<\\\n\t "
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (do ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\\'
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' (() ()
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m ()
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
rawTeXBlock)
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\\')
return $ return $ B.str $! T.singleton result
code :: PandocMonad m => MarkdownParser m (F Inlines)
code :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
code = ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
starts <- ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'`')
skipSpaces
result <- trim . T.concat
<$> manyTill
( many1Char (noneOf "`\n")
<|> many1Char (char '`')
<|> (char '\n'
>> notFollowedBy (inList >> listStart)
>> notFollowedBy' blankline
>> return " "))
(try $ skipSpaces
>> count (length starts) (char '`')
>> notFollowedBy (char '`'))
rawattr <-
(Left <$> (guardEnabled Ext_raw_attribute >> try rawAttribute))
<|>
(Right <$> option ("",[],[])
(guardEnabled Ext_inline_code_attributes >> try attributes))
return $ return $
case rawattr of
Left Text
syn -> Text -> Text -> Inlines
B.rawInline Text
syn (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$! Text
result
Right Attr
attr -> Attr -> Text -> Inlines
B.codeWith Attr
attr (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$! Text
result
math :: PandocMonad m => MarkdownParser m (F Inlines)
math :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
math = (Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> (Text -> Inlines) -> Text -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.displayMath (Text -> F Inlines)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Sources ParserState m Text
forall st s (m :: * -> *).
(HasReaderOptions st, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
mathDisplay ParsecT Sources ParserState m Text
-> (Text -> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
forall a b.
ParsecT Sources ParserState m a
-> (a -> ParsecT Sources ParserState m b)
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> ParsecT Sources ParserState m Text
forall (m :: * -> *) s.
(PandocMonad m, HasMacros s, HasReaderOptions s) =>
Text -> ParsecT Sources s m Text
applyMacros))
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> (Text -> Inlines) -> Text -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.math (Text -> F Inlines)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Sources ParserState m Text
forall st s (m :: * -> *).
(HasReaderOptions st, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
mathInline ParsecT Sources ParserState m Text
-> (Text -> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
forall a b.
ParsecT Sources ParserState m a
-> (a -> ParsecT Sources ParserState m b)
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> ParsecT Sources ParserState m Text
forall (m :: * -> *) s.
(PandocMonad m, HasMacros s, HasReaderOptions s) =>
Text -> ParsecT Sources s m Text
applyMacros)) ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a s st (m :: * -> *).
Monoid a =>
ParsecT s st m a -> ParsecT s st m a -> ParsecT s st m a
<+?>
(Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_smart ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines)
-> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Inlines
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Inlines
apostrophe)
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
space ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Char -> Bool) -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isPunctuation))
enclosure :: PandocMonad m
=> Char
-> MarkdownParser m (F Inlines)
enclosure :: forall (m :: * -> *).
PandocMonad m =>
Char -> MarkdownParser m (F Inlines)
enclosure Char
c = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardDisabled Extension
Ext_intraword_underscores
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Bool -> ParsecT Sources ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'*')
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Bool -> ParsecT Sources ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ParsecT Sources ParserState m Bool
forall s (m :: * -> *) a st.
(Stream s m a, HasLastStrPosition st) =>
ParsecT s st m Bool
notAfterString)
cs <- ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c)
(return (B.str cs) <>) <$> whitespace
<|>
case T.length cs of
Int
3 -> Char -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Char -> MarkdownParser m (F Inlines)
three Char
c
Int
2 -> Char -> F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Char -> F Inlines -> MarkdownParser m (F Inlines)
two Char
c F Inlines
forall a. Monoid a => a
mempty
Int
1 -> Char -> F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Char -> F Inlines -> MarkdownParser m (F Inlines)
one Char
c F Inlines
forall a. Monoid a => a
mempty
Int
_ -> F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
cs)
ender :: PandocMonad m => Char -> Int -> MarkdownParser m ()
ender :: forall (m :: * -> *).
PandocMonad m =>
Char -> Int -> MarkdownParser m ()
ender Char
c Int
n = ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ do
Int
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m FilePath
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
n (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c)
Bool -> ParsecT Sources ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'*')
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardDisabled Extension
Ext_intraword_underscores
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum
three :: PandocMonad m => Char -> MarkdownParser m (F Inlines)
three :: forall (m :: * -> *).
PandocMonad m =>
Char -> MarkdownParser m (F Inlines)
three Char
c = do
contents <- [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Char -> Int -> ParsecT Sources ParserState m ()
forall (m :: * -> *).
PandocMonad m =>
Char -> Int -> MarkdownParser m ()
ender Char
c Int
1) ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inline)
(ender c 3 >> updateLastStrPos >> return (B.strong . B.emph <$> contents))
<|> (ender c 2 >> updateLastStrPos >> one c (B.strong <$> contents))
<|> (ender c 1 >> updateLastStrPos >> two c (B.emph <$> contents))
<|> return (return (B.str $ T.pack [c,c,c]) <> contents)
two :: PandocMonad m => Char -> F Inlines -> MarkdownParser m (F Inlines)
two :: forall (m :: * -> *).
PandocMonad m =>
Char -> F Inlines -> MarkdownParser m (F Inlines)
two Char
c F Inlines
prefix' = do
contents <- [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Char -> Int -> ParsecT Sources ParserState m ()
forall (m :: * -> *).
PandocMonad m =>
Char -> Int -> MarkdownParser m ()
ender Char
c Int
2) ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inline)
(ender c 2 >> updateLastStrPos >>
return (B.strong <$> (prefix' <> contents)))
<|> return (return (B.str $ T.pack [c,c]) <> (prefix' <> contents))
one :: PandocMonad m => Char -> F Inlines -> MarkdownParser m (F Inlines)
one :: forall (m :: * -> *).
PandocMonad m =>
Char -> F Inlines -> MarkdownParser m (F Inlines)
one Char
c F Inlines
prefix' = do
contents <- [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ( (ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Char -> Int -> ParsecT Sources ParserState m ()
forall (m :: * -> *).
PandocMonad m =>
Char -> Int -> MarkdownParser m ()
ender Char
c Int
1) ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inline)
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (FilePath -> ParsecT Sources ParserState m 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] ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Char -> Int -> ParsecT Sources ParserState m ()
forall (m :: * -> *).
PandocMonad m =>
Char -> Int -> MarkdownParser m ()
ender Char
c Int
1) ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
Char -> F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Char -> F Inlines -> MarkdownParser m (F Inlines)
two Char
c F Inlines
forall a. Monoid a => a
mempty) )
(ender c 1 >> updateLastStrPos >> return (B.emph <$> (prefix' <> contents)))
<|> return (return (B.str $ T.singleton c) <> (prefix' <> contents))
strongOrEmph :: PandocMonad m => MarkdownParser m (F Inlines)
strongOrEmph :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
strongOrEmph = Char -> MarkdownParser m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Char -> MarkdownParser m (F Inlines)
enclosure Char
'*' MarkdownParser m (F Inlines)
-> MarkdownParser m (F Inlines) -> MarkdownParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> MarkdownParser m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Char -> MarkdownParser m (F Inlines)
enclosure Char
'_'
inlinesBetween :: PandocMonad m
=> (Show b)
=> MarkdownParser m a
-> MarkdownParser m b
-> MarkdownParser m (F Inlines)
inlinesBetween :: forall (m :: * -> *) b a.
(PandocMonad m, Show b) =>
MarkdownParser m a
-> MarkdownParser m b -> MarkdownParser m (F Inlines)
inlinesBetween MarkdownParser m a
start MarkdownParser m b
end =
F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m [F Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MarkdownParser m a
start MarkdownParser m a
-> ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m [F Inlines]
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m (F Inlines)
-> MarkdownParser m b -> ParsecT Sources ParserState m [F Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
many1Till ParsecT Sources ParserState m (F Inlines)
inner MarkdownParser m b
end)
where inner :: ParsecT Sources ParserState m (F Inlines)
inner = ParsecT Sources ParserState m (F Inlines)
innerSpace ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
(ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' (() ()
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m ()
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
whitespace) ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inline)
innerSpace :: ParsecT Sources ParserState m (F Inlines)
innerSpace = ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
whitespace ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* MarkdownParser m b -> ParsecT Sources ParserState m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' MarkdownParser m b
end
strikeout :: PandocMonad m => MarkdownParser m (F Inlines)
strikeout :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
strikeout = (Inlines -> Inlines) -> F Inlines -> F Inlines
forall a b.
(a -> b) -> Future ParserState a -> Future ParserState b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.strikeout (F Inlines -> F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_strikeout ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m ()
-> MarkdownParser m FilePath
-> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *) b a.
(PandocMonad m, Show b) =>
MarkdownParser m a
-> MarkdownParser m b -> MarkdownParser m (F Inlines)
inlinesBetween ParsecT Sources ParserState m ()
forall {u}. ParsecT Sources u m ()
strikeStart MarkdownParser m FilePath
forall {u}. ParsecT Sources u m FilePath
strikeEnd)
where strikeStart :: ParsecT Sources u m ()
strikeStart = FilePath -> ParsecT Sources u m FilePath
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m FilePath
string FilePath
"~~" ParsecT Sources u m FilePath
-> ParsecT Sources u m Char -> ParsecT Sources u m Char
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m Char -> ParsecT Sources u m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ParsecT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
nonspaceChar
ParsecT Sources u m Char
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m Char -> ParsecT Sources u m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Char -> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'~')
strikeEnd :: ParsecT Sources u m FilePath
strikeEnd = ParsecT Sources u m FilePath -> ParsecT Sources u m FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources u m FilePath -> ParsecT Sources u m FilePath)
-> ParsecT Sources u m FilePath -> ParsecT Sources u m FilePath
forall a b. (a -> b) -> a -> b
$ FilePath -> ParsecT Sources u m FilePath
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m FilePath
string FilePath
"~~"
mark :: PandocMonad m => MarkdownParser m (F Inlines)
mark :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
mark = (Inlines -> Inlines) -> F Inlines -> F Inlines
forall a b.
(a -> b) -> Future ParserState a -> Future ParserState b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Attr -> Inlines -> Inlines
B.spanWith (Text
"",[Text
"mark"],[])) (F Inlines -> F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_mark ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m ()
-> MarkdownParser m FilePath
-> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *) b a.
(PandocMonad m, Show b) =>
MarkdownParser m a
-> MarkdownParser m b -> MarkdownParser m (F Inlines)
inlinesBetween ParsecT Sources ParserState m ()
forall {u}. ParsecT Sources u m ()
markStart MarkdownParser m FilePath
forall {u}. ParsecT Sources u m FilePath
markEnd)
where markStart :: ParsecT Sources u m ()
markStart = FilePath -> ParsecT Sources u m FilePath
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m FilePath
string FilePath
"==" ParsecT Sources u m FilePath
-> ParsecT Sources u m Char -> ParsecT Sources u m Char
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m Char -> ParsecT Sources u m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ParsecT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
nonspaceChar
ParsecT Sources u m Char
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m Char -> ParsecT Sources u m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Char -> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'=')
markEnd :: ParsecT Sources u m FilePath
markEnd = ParsecT Sources u m FilePath -> ParsecT Sources u m FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources u m FilePath -> ParsecT Sources u m FilePath)
-> ParsecT Sources u m FilePath -> ParsecT Sources u m FilePath
forall a b. (a -> b) -> a -> b
$ FilePath -> ParsecT Sources u m FilePath
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m FilePath
string FilePath
"=="
superscript :: PandocMonad m => MarkdownParser m (F Inlines)
superscript :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
superscript = do
(Inlines -> Inlines) -> F Inlines -> F Inlines
forall a b.
(a -> b) -> Future ParserState a -> Future ParserState b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.superscript (F Inlines -> F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'^'
[F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m [F Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Sources ParserState m [F Inlines]
regularSuperscript ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m [F Inlines]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m [F Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Sources ParserState m [F Inlines]
mmdShortSuperscript))
where regularSuperscript :: ParsecT Sources ParserState m [F Inlines]
regularSuperscript = ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [F Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
many1Till (do Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_superscript
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inline) (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'^')
mmdShortSuperscript :: ParsecT Sources ParserState m [F Inlines]
mmdShortSuperscript = do Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_short_subsuperscripts
result <- FilePath -> Text
T.pack (FilePath -> Text)
-> ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum
return $ return $ return $ B.str result
subscript :: PandocMonad m => MarkdownParser m (F Inlines)
subscript :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
subscript = do
(Inlines -> Inlines) -> F Inlines -> F Inlines
forall a b.
(a -> b) -> Future ParserState a -> Future ParserState b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.subscript (F Inlines -> F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'~'
[F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m [F Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Sources ParserState m [F Inlines]
regularSubscript ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m [F Inlines]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m [F Inlines]
mmdShortSubscript))
where regularSubscript :: ParsecT Sources ParserState m [F Inlines]
regularSubscript = ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [F Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
many1Till (do Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_subscript
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inline) (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'~')
mmdShortSubscript :: ParsecT Sources ParserState m [F Inlines]
mmdShortSubscript = do Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_short_subsuperscripts
result <- FilePath -> Text
T.pack (FilePath -> Text)
-> ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum
return $ return $ return $ B.str result
whitespace :: PandocMonad m => MarkdownParser m (F Inlines)
whitespace :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
whitespace = ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines)
-> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Sources ParserState m Inlines
lb ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Inlines
forall {u}. ParsecT Sources u m Inlines
regsp) ParsecT Sources ParserState m (F Inlines)
-> FilePath -> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> FilePath -> ParsecT s u m a
<?> FilePath
"whitespace"
where lb :: ParsecT Sources ParserState m Inlines
lb = ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m Inlines
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines
-> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m Inlines
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Inlines
B.space (ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
endline ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m Inlines
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> ParsecT Sources ParserState m Inlines
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.linebreak)
regsp :: ParsecT Sources u m Inlines
regsp = ParsecT Sources u m Char -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar ParsecT Sources u m ()
-> ParsecT Sources u m Inlines -> ParsecT Sources u m Inlines
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> ParsecT Sources u m Inlines
forall a. a -> ParsecT Sources u m a
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.space
nonEndline :: PandocMonad m => ParsecT Sources st m Char
nonEndline :: forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m Char
nonEndline = (Char -> Bool) -> ParsecT Sources st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/=Char
'\n')
str :: PandocMonad m => MarkdownParser m (F Inlines)
str :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
str = do
!result <- [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat ([Text] -> Text)
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1
( FilePath -> Text
T.pack (FilePath -> Text)
-> ParsecT Sources ParserState m FilePath
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum)
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text
"." Text
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'.' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Char
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'.')) )
updateLastStrPos
(do guardEnabled Ext_smart
abbrevs <- getOption readerAbbreviations
if result `Set.member` abbrevs
then try (do ils <- whitespace
notFollowedBy (() <$ cite <|> () <$ note)
return $ do
ils' <- ils
case B.toList ils' of
[Inline
Space] ->
Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$! (Text -> Inlines
B.str Text
result Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
B.str Text
"\160")
[Inline]
_ -> Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$! (Text -> Inlines
B.str Text
result Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
ils'))
<|> return (return $! B.str result)
else return (return $! B.str result))
<|> return (return $! B.str result)
endline :: PandocMonad m => MarkdownParser m (F Inlines)
endline :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
endline = ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState ParsecT Sources ParserState m ParserState
-> (ParserState -> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> (a -> ParsecT Sources ParserState m b)
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> ParsecT Sources ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Sources ParserState m ())
-> (ParserState -> Bool)
-> ParserState
-> ParsecT Sources ParserState m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParserState -> Bool
stateAllowLineBreaks
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
inList ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
listStart)
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardDisabled Extension
Ext_lists_without_preceding_blankline ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
listStart
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_blank_before_blockquote ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall (m :: * -> *). PandocMonad m => MarkdownParser m Char
emailBlockQuoteStart
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_blank_before_header ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ())
-> (Char -> ParsecT Sources ParserState m Char)
-> Char
-> ParsecT Sources ParserState m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char (Char -> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ParsecT Sources ParserState m Char
forall (m :: * -> *). PandocMonad m => MarkdownParser m Char
atxChar)
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardDisabled Extension
Ext_backtick_code_blocks ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (() ()
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m ()
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'`') ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m (Future ParserState Blocks)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
codeBlockFenced))
ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
notFollowedByHtmlCloser
ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
notFollowedByDivCloser
(ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return F Inlines
forall a. Monoid a => a
mempty)
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_hard_line_breaks ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.linebreak))
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_ignore_line_breaks ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return F Inlines
forall a. Monoid a => a
mempty)
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.softbreak))
reference :: PandocMonad m => MarkdownParser m (F Inlines, Text)
reference :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (F Inlines, Text)
reference = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardDisabled Extension
Ext_footnotes ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
noteMarker
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines, Text)
forall (m :: * -> *) st a.
Monad m =>
ParsecT Sources st m a -> ParsecT Sources st m (a, Text)
withRaw (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines, Text))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines, Text)
forall a b. (a -> b) -> a -> b
$ F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *) a.
PandocMonad m =>
MarkdownParser m (F a) -> MarkdownParser m (F a)
inBalancedBrackets ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inlines
parenthesizedChars :: PandocMonad m => MarkdownParser m Text
parenthesizedChars :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
parenthesizedChars = do
result <- Char
-> Char
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
Char -> Char -> ParsecT s st m Text -> ParsecT s st m Text
charsInBalanced Char
'(' Char
')' ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
litChar
return $ "(" <> result <> ")"
source :: PandocMonad m => MarkdownParser m (Text, Text)
source :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Target
source = do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'('
ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
let urlChunk :: ParsecT Sources ParserState m Text
urlChunk =
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
parenthesizedChars
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (FilePath -> ParsecT Sources ParserState m 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 m ()
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
litChar)
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Text
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (FilePath -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
oneOf FilePath
"\"')"))
let sourceURL :: ParsecT Sources ParserState m Text
sourceURL = [Text] -> Text
T.unwords ([Text] -> Text) -> ([Text] -> [Text]) -> [Text] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Text]
T.words (Text -> [Text]) -> ([Text] -> Text) -> [Text] -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Text
T.concat ([Text] -> Text)
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Sources ParserState m Text
urlChunk
let betweenAngles :: ParsecT Sources ParserState m Text
betweenAngles = ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'<' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat ([Text] -> Text)
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Text]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
manyTill ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
litChar (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'>'))
src <- ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Sources ParserState m Text
betweenAngles ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Sources ParserState m Text
forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m Text
base64DataURI ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Text
sourceURL
tit <- option "" $ try $ spnl >> linkTitle
skipSpaces
char ')'
return (escapeURI $ trimr src, tit)
base64DataURI :: PandocMonad m => ParsecT Sources s m Text
base64DataURI :: forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m Text
base64DataURI = do
Sources ((pos, txt):rest) <- ParsecT Sources s m Sources
forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput
let r = Parser Text -> Text -> Result Text
forall a. Parser a -> Text -> Result a
A.parse ((Text, (ByteString, Text)) -> Text
forall a b. (a, b) -> a
fst ((Text, (ByteString, Text)) -> Text)
-> Parser Text (Text, (ByteString, Text)) -> Parser Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (ByteString, Text) -> Parser Text (Text, (ByteString, Text))
forall a. Parser a -> Parser (Text, a)
A.match Parser (ByteString, Text)
pBase64DataURI) Text
txt
case r of
A.Done Text
remaining Text
consumed -> do
let pos' :: SourcePos
pos' = SourcePos -> Int -> SourcePos
incSourceColumn SourcePos
pos (Text -> Int
T.length Text
consumed)
Sources -> ParsecT Sources s m ()
forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput (Sources -> ParsecT Sources s m ())
-> Sources -> ParsecT Sources s m ()
forall a b. (a -> b) -> a -> b
$ [(SourcePos, Text)] -> Sources
Sources ((SourcePos
pos', Text
remaining)(SourcePos, Text) -> [(SourcePos, Text)] -> [(SourcePos, Text)]
forall a. a -> [a] -> [a]
:[(SourcePos, Text)]
rest)
Text -> ParsecT Sources s m Text
forall a. a -> ParsecT Sources s m a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
consumed
Result Text
_ -> ParsecT Sources s m Text
forall a. ParsecT Sources s m a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
linkTitle :: PandocMonad m => MarkdownParser m Text
linkTitle :: forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
linkTitle = Char -> MarkdownParser m Text
forall (m :: * -> *).
PandocMonad m =>
Char -> MarkdownParser m Text
quotedTitle Char
'"' MarkdownParser m Text
-> MarkdownParser m Text -> MarkdownParser m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> MarkdownParser m Text
forall (m :: * -> *).
PandocMonad m =>
Char -> MarkdownParser m Text
quotedTitle Char
'\''
wikilink :: PandocMonad m
=> (Attr -> Text -> Text -> Inlines -> Inlines)
-> MarkdownParser m (F Inlines)
wikilink :: forall (m :: * -> *).
PandocMonad m =>
(Attr -> Text -> Text -> Inlines -> Inlines)
-> MarkdownParser m (F Inlines)
wikilink Attr -> Text -> Text -> Inlines -> Inlines
constructor = do
titleAfter <-
(Bool
True Bool
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Bool
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_wikilinks_title_after_pipe) ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
(Bool
False Bool
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Bool
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_wikilinks_title_before_pipe)
try $ do
string "[[" *> notFollowedBy' (char '[')
raw <- many1TillChar anyChar (try $ string "]]")
let (title, url) = case T.break (== '|') raw of
(Text
before, Text
"") -> (Text
before, Text
before)
(Text
before, Text
after)
| Bool
titleAfter -> (Int -> Text -> Text
T.drop Int
1 Text
after, Text
before)
| Bool
otherwise -> (Text
before, Int -> Text -> Text
T.drop Int
1 Text
after)
guard $ T.all (`notElem` ['\n','\r','\f','\t']) url
return . pure . constructor nullAttr url "wikilink" $
B.text $ fromEntities title
link :: PandocMonad m => MarkdownParser m (F Inlines)
link :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
link = ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
st <- ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
guard $ stateAllowLinks st
setState $ st{ stateAllowLinks = False }
(lab,raw) <- reference
setState $ st{ stateAllowLinks = True }
regLink B.linkWith lab <|> referenceLink B.linkWith (lab,raw)
bracketedSpan :: PandocMonad m => MarkdownParser m (F Inlines)
bracketedSpan :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
bracketedSpan = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_bracketed_spans
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
(lab,_) <- MarkdownParser m (F Inlines, Text)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (F Inlines, Text)
reference
attr <- attributes
return $ wrapSpan attr <$> lab
wrapSpan :: Attr -> Inlines -> Inlines
wrapSpan :: Attr -> Inlines -> Inlines
wrapSpan (Text
ident, [Text]
classes, [Target]
kvs) =
let (Maybe (Inlines -> Inlines)
initConst, [Target]
kvs') = case Text -> [Target] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"style" [Target]
kvs of
Just Text
s | Text -> Bool
isSmallCapsFontVariant Text
s ->
let kvsNoStyle :: [Target]
kvsNoStyle = [(Text
k, Text
v) | (Text
k, Text
v) <- [Target]
kvs, Text
k Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"style"]
in ((Inlines -> Inlines) -> Maybe (Inlines -> Inlines)
forall a. a -> Maybe a
Just Inlines -> Inlines
B.smallcaps, [Target]
kvsNoStyle)
Maybe Text
_ -> (Maybe (Inlines -> Inlines)
forall a. Maybe a
Nothing, [Target]
kvs)
(Maybe (Inlines -> Inlines)
mConstr, [Text]
remainingClasses) = (Text
-> (Maybe (Inlines -> Inlines), [Text])
-> (Maybe (Inlines -> Inlines), [Text]))
-> (Maybe (Inlines -> Inlines), [Text])
-> [Text]
-> (Maybe (Inlines -> Inlines), [Text])
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Text
-> (Maybe (Inlines -> Inlines), [Text])
-> (Maybe (Inlines -> Inlines), [Text])
forall {a}.
(Eq a, IsString a) =>
a
-> (Maybe (Inlines -> Inlines), [a])
-> (Maybe (Inlines -> Inlines), [a])
go (Maybe (Inlines -> Inlines)
initConst, []) [Text]
classes
wrapInConstr :: (b -> c) -> Maybe (b -> b) -> b -> c
wrapInConstr b -> c
c = (b -> c) -> ((b -> b) -> b -> c) -> Maybe (b -> b) -> b -> c
forall b a. b -> (a -> b) -> Maybe a -> b
maybe b -> c
c (b -> c
c (b -> c) -> (b -> b) -> b -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
.)
go :: a
-> (Maybe (Inlines -> Inlines), [a])
-> (Maybe (Inlines -> Inlines), [a])
go a
cls (Maybe (Inlines -> Inlines)
accConstr, [a]
other) =
case a
cls of
a
"smallcaps" -> ((Inlines -> Inlines) -> Maybe (Inlines -> Inlines)
forall a. a -> Maybe a
Just ((Inlines -> Inlines) -> Maybe (Inlines -> Inlines))
-> (Inlines -> Inlines) -> Maybe (Inlines -> Inlines)
forall a b. (a -> b) -> a -> b
$ (Inlines -> Inlines)
-> Maybe (Inlines -> Inlines) -> Inlines -> Inlines
forall {b} {c}. (b -> c) -> Maybe (b -> b) -> b -> c
wrapInConstr Inlines -> Inlines
B.smallcaps Maybe (Inlines -> Inlines)
accConstr, [a]
other)
a
"ul" -> ((Inlines -> Inlines) -> Maybe (Inlines -> Inlines)
forall a. a -> Maybe a
Just ((Inlines -> Inlines) -> Maybe (Inlines -> Inlines))
-> (Inlines -> Inlines) -> Maybe (Inlines -> Inlines)
forall a b. (a -> b) -> a -> b
$ (Inlines -> Inlines)
-> Maybe (Inlines -> Inlines) -> Inlines -> Inlines
forall {b} {c}. (b -> c) -> Maybe (b -> b) -> b -> c
wrapInConstr Inlines -> Inlines
B.underline Maybe (Inlines -> Inlines)
accConstr, [a]
other)
a
"underline" -> ((Inlines -> Inlines) -> Maybe (Inlines -> Inlines)
forall a. a -> Maybe a
Just ((Inlines -> Inlines) -> Maybe (Inlines -> Inlines))
-> (Inlines -> Inlines) -> Maybe (Inlines -> Inlines)
forall a b. (a -> b) -> a -> b
$ (Inlines -> Inlines)
-> Maybe (Inlines -> Inlines) -> Inlines -> Inlines
forall {b} {c}. (b -> c) -> Maybe (b -> b) -> b -> c
wrapInConstr Inlines -> Inlines
B.underline Maybe (Inlines -> Inlines)
accConstr, [a]
other)
a
_ -> (Maybe (Inlines -> Inlines)
accConstr, a
clsa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
other)
in case (Text
ident, [Text]
remainingClasses, [Target]
kvs') of
(Text
"", [], []) -> (Inlines -> Inlines)
-> Maybe (Inlines -> Inlines) -> Inlines -> Inlines
forall a. a -> Maybe a -> a
fromMaybe (Attr -> Inlines -> Inlines
B.spanWith Attr
nullAttr) Maybe (Inlines -> Inlines)
mConstr
Attr
attr -> (Inlines -> Inlines)
-> Maybe (Inlines -> Inlines) -> Inlines -> Inlines
forall {b} {c}. (b -> c) -> Maybe (b -> b) -> b -> c
wrapInConstr (Attr -> Inlines -> Inlines
B.spanWith Attr
attr) Maybe (Inlines -> Inlines)
mConstr
isSmallCapsFontVariant :: Text -> Bool
isSmallCapsFontVariant :: Text -> Bool
isSmallCapsFontVariant Text
s =
Text -> Text
T.toLower ((Char -> Bool) -> Text -> Text
T.filter (Char -> FilePath -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Char
' ', Char
'\t', Char
';']) Text
s) Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
==
Text
"font-variant:small-caps"
regLink :: PandocMonad m
=> (Attr -> Text -> Text -> Inlines -> Inlines)
-> F Inlines
-> MarkdownParser m (F Inlines)
regLink :: forall (m :: * -> *).
PandocMonad m =>
(Attr -> Text -> Text -> Inlines -> Inlines)
-> F Inlines -> MarkdownParser m (F Inlines)
regLink Attr -> Text -> Text -> Inlines -> Inlines
constructor F Inlines
lab = ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
(!src, !tit) <- MarkdownParser m Target
forall (m :: * -> *). PandocMonad m => MarkdownParser m Target
source
rebase <- option False (True <$ guardEnabled Ext_rebase_relative_paths)
pos <- getPosition
let !src' = if Bool
rebase then SourcePos -> Text -> Text
rebasePath SourcePos
pos Text
src else Text
src
!attr <- option nullAttr $ guardEnabled Ext_link_attributes >> attributes
return $ constructor attr src' tit <$> lab
referenceLink :: PandocMonad m
=> (Attr -> Text -> Text -> Inlines -> Inlines)
-> (F Inlines, Text)
-> MarkdownParser m (F Inlines)
referenceLink :: forall (m :: * -> *).
PandocMonad m =>
(Attr -> Text -> Text -> Inlines -> Inlines)
-> (F Inlines, Text) -> MarkdownParser m (F Inlines)
referenceLink Attr -> Text -> Text -> Inlines -> Inlines
constructor (F Inlines
lab, Text
raw) = do
sp <- (Bool
True Bool
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Bool
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
' ')) ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Bool -> ParsecT Sources ParserState m Bool
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
(_,!raw') <- option (mempty, "") $
lookAhead (try (do guardEnabled Ext_citations
guardDisabled Ext_spaced_reference_links <|> spnl
normalCite
return (mempty, "")))
<|>
try ((guardDisabled Ext_spaced_reference_links <|> spnl) >> reference)
when (raw' == "") $ guardEnabled Ext_shortcut_reference_links
!attr <- option nullAttr $ guardEnabled Ext_link_attributes >> attributes
let !labIsRef = Text
raw' Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"" Bool -> Bool -> Bool
|| Text
raw' Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"[]"
let (exclam, rawsuffix) =
case T.uncons raw of
Just (Char
'!', Text
rest) -> (Bool
True, Text
rest)
Maybe (Char, Text)
_ -> (Bool
False, Text
raw)
let !key = Text -> Key
toKey (Text -> Key) -> Text -> Key
forall a b. (a -> b) -> a -> b
$ if Bool
labIsRef then Text
rawsuffix else Text
raw'
parsedRaw <- parseFromString' inlines raw'
fallback <- parseFromString' inlines $ if exclam
then rawsuffix
else dropBrackets rawsuffix
implicitHeaderRefs <- option False $
True <$ guardEnabled Ext_implicit_header_references
let makeFallback = do
parsedRaw' <- F Inlines
parsedRaw
fallback' <- fallback
return $ (if exclam
then "!" <> fallback'
else B.str "[" <> fallback' <> B.str "]") <>
(if sp && not (T.null raw) then B.space else mempty) <>
parsedRaw'
return $ do
keys <- asksF stateKeys
case M.lookup key keys of
Maybe (Target, Attr)
Nothing ->
if Bool
implicitHeaderRefs
then do
headerKeys <- (ParserState -> KeyTable) -> Future ParserState KeyTable
forall s a. (s -> a) -> Future s a
asksF ParserState -> KeyTable
stateHeaderKeys
case M.lookup key headerKeys of
Just ((Text
src, Text
tit), Attr
_) -> Attr -> Text -> Text -> Inlines -> Inlines
constructor Attr
attr Text
src Text
tit (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Inlines
lab
Maybe (Target, Attr)
Nothing -> F Inlines
makeFallback
else F Inlines
makeFallback
Just ((Text
src,Text
tit), Attr
defattr) ->
Attr -> Text -> Text -> Inlines -> Inlines
constructor (Attr -> Attr -> Attr
combineAttr Attr
attr Attr
defattr) Text
src Text
tit (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Inlines
lab
dropBrackets :: Text -> Text
dropBrackets :: Text -> Text
dropBrackets = Text -> Text
dropRB (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
dropLB
where dropRB :: Text -> Text
dropRB (Text -> Maybe (Text, Char)
T.unsnoc -> Just (Text
xs,Char
']')) = Text
xs
dropRB Text
xs = Text
xs
dropLB :: Text -> Text
dropLB (Text -> Maybe (Char, Text)
T.uncons -> Just (Char
'[',Text
xs)) = Text
xs
dropLB Text
xs = Text
xs
bareURL :: PandocMonad m => MarkdownParser m (F Inlines)
bareURL :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
bareURL = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_autolink_bare_uris
ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState ParsecT Sources ParserState m ParserState
-> (ParserState -> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> (a -> ParsecT Sources ParserState m b)
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> ParsecT Sources ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Sources ParserState m ())
-> (ParserState -> Bool)
-> ParserState
-> ParsecT Sources ParserState m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParserState -> Bool
stateAllowLinks
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
(cls, (orig, src)) <- ((Text
"uri",) (Target -> (Text, Target))
-> ParsecT Sources ParserState m Target
-> ParsecT Sources ParserState m (Text, Target)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Target
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Target
uri) ParsecT Sources ParserState m (Text, Target)
-> ParsecT Sources ParserState m (Text, Target)
-> ParsecT Sources ParserState m (Text, Target)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ((Text
"email",) (Target -> (Text, Target))
-> ParsecT Sources ParserState m Target
-> ParsecT Sources ParserState m (Text, Target)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Target
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Target
emailAddress)
notFollowedBy $ try $ spaces >> htmlTag (~== TagClose ("a" :: Text))
return $ return $ B.linkWith ("",[cls],[]) src "" (B.str orig)
autoLink :: PandocMonad m => MarkdownParser m (F Inlines)
autoLink :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
autoLink = ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState ParsecT Sources ParserState m ParserState
-> (ParserState -> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> (a -> ParsecT Sources ParserState m b)
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> ParsecT Sources ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Sources ParserState m ())
-> (ParserState -> Bool)
-> ParserState
-> ParsecT Sources ParserState m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParserState -> Bool
stateAllowLinks
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'<'
(cls, (orig, src)) <- ((Text
"uri",) (Target -> (Text, Target))
-> ParsecT Sources ParserState m Target
-> ParsecT Sources ParserState m (Text, Target)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Target
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Target
uri) ParsecT Sources ParserState m (Text, Target)
-> ParsecT Sources ParserState m (Text, Target)
-> ParsecT Sources ParserState m (Text, Target)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ((Text
"email",) (Target -> (Text, Target))
-> ParsecT Sources ParserState m Target
-> ParsecT Sources ParserState m (Text, Target)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Target
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Target
emailAddress)
extra <- fromEntities <$> manyTillChar nonspaceChar (char '>')
attr <- option ("", [cls], []) $ try $
guardEnabled Ext_link_attributes >> attributes
return $ return $ B.linkWith attr (src <> escapeURI extra) ""
(B.str $ orig <> extra)
rebasePath :: SourcePos -> Text -> Text
rebasePath :: SourcePos -> Text -> Text
rebasePath SourcePos
pos Text
path = do
let fp :: FilePath
fp = SourcePos -> FilePath
sourceName SourcePos
pos
isFragment :: Bool
isFragment = Int -> Text -> Text
T.take Int
1 Text
path Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"#"
path' :: FilePath
path' = Text -> FilePath
T.unpack Text
path
isAbsolutePath :: Bool
isAbsolutePath = FilePath -> Bool
Posix.isAbsolute FilePath
path' Bool -> Bool -> Bool
|| FilePath -> Bool
Windows.isAbsolute FilePath
path'
in if Text -> Bool
T.null Text
path Bool -> Bool -> Bool
|| Bool
isFragment Bool -> Bool -> Bool
|| Bool
isAbsolutePath Bool -> Bool -> Bool
|| Text -> Bool
isURI Text
path
then Text
path
else
case FilePath -> FilePath
takeDirectory FilePath
fp of
FilePath
"" -> Text
path
FilePath
"." -> Text
path
FilePath
d -> FilePath -> Text
T.pack FilePath
d Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
path
image :: PandocMonad m => MarkdownParser m (F Inlines)
image :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
image = ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'!'
(Attr -> Text -> Text -> Inlines -> Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
(Attr -> Text -> Text -> Inlines -> Inlines)
-> MarkdownParser m (F Inlines)
wikilink Attr -> Text -> Text -> Inlines -> Inlines
B.imageWith ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
do (lab,raw) <- MarkdownParser m (F Inlines, Text)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (F Inlines, Text)
reference
defaultExt <- getOption readerDefaultImageExtension
let constructor Attr
attr' Text
src
| Text
"data:" Text -> Text -> Bool
`T.isPrefixOf` Text
src = Attr -> Text -> Text -> Inlines -> Inlines
B.imageWith Attr
attr' Text
src
| Bool
otherwise =
case FilePath -> FilePath
takeExtension (Text -> FilePath
T.unpack Text
src) of
FilePath
"" -> Attr -> Text -> Text -> Inlines -> Inlines
B.imageWith Attr
attr' (FilePath -> Text
T.pack (FilePath -> Text) -> FilePath -> Text
forall a b. (a -> b) -> a -> b
$ FilePath -> FilePath -> FilePath
addExtension (Text -> FilePath
T.unpack Text
src)
(FilePath -> FilePath) -> FilePath -> FilePath
forall a b. (a -> b) -> a -> b
$ Text -> FilePath
T.unpack Text
defaultExt)
FilePath
_ -> Attr -> Text -> Text -> Inlines -> Inlines
B.imageWith Attr
attr' Text
src
regLink constructor lab <|> referenceLink constructor (lab, "!" <> raw)
note :: PandocMonad m => MarkdownParser m (F Inlines)
note :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
note = ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_footnotes
ref <- MarkdownParser m Text
forall (m :: * -> *). PandocMonad m => MarkdownParser m Text
noteMarker
updateState $ \ParserState
st -> ParserState
st{ stateNoteRefs = Set.insert ref (stateNoteRefs st)
, stateNoteNumber = stateNoteNumber st + 1 }
noteNum <- stateNoteNumber <$> getState
return $ do
notes <- asksF stateNotes'
case M.lookup ref notes of
Maybe (SourcePos, Future ParserState Blocks)
Nothing -> Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ Text
"[^" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
ref Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"]"
Just (SourcePos
_pos, Future ParserState Blocks
contents) -> do
st <- Future ParserState ParserState
forall s. Future s s
askF
let contents' = Future ParserState Blocks -> ParserState -> Blocks
forall s a. Future s a -> s -> a
runF Future ParserState Blocks
contents ParserState
st{ stateNotes' = M.empty }
let addCitationNoteNum c :: Citation
c@Citation{} =
Citation
c{ citationNoteNum = noteNum }
let adjustCite (Cite [Citation]
cs [Inline]
ils) =
[Citation] -> [Inline] -> Inline
Cite ((Citation -> Citation) -> [Citation] -> [Citation]
forall a b. (a -> b) -> [a] -> [b]
map Citation -> Citation
addCitationNoteNum [Citation]
cs) [Inline]
ils
adjustCite Inline
x = Inline
x
return $ B.note $ walk adjustCite contents'
inlineNote :: PandocMonad m => MarkdownParser m (F Inlines)
inlineNote :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inlineNote = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_inline_notes
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'^'
(ParserState -> ParserState) -> ParsecT Sources ParserState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((ParserState -> ParserState) -> ParsecT Sources ParserState m ())
-> (ParserState -> ParserState) -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ \ParserState
st -> ParserState
st{ stateInNote = True
, stateNoteNumber = stateNoteNumber st + 1 }
contents <- ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *) a.
PandocMonad m =>
MarkdownParser m (F a) -> MarkdownParser m (F a)
inBalancedBrackets ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inlines
updateState $ \ParserState
st -> ParserState
st{ stateInNote = False }
return $ B.note . B.para <$> contents
rawLaTeXInline' :: PandocMonad m => MarkdownParser m (F Inlines)
rawLaTeXInline' :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
rawLaTeXInline' = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_raw_tex
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' ParsecT Sources ParserState m Text
forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m Text
rawConTeXtEnvironment
!s <- ParsecT Sources ParserState m Text
forall (m :: * -> *) s.
(PandocMonad m, HasMacros s, HasReaderOptions s) =>
ParsecT Sources s m Text
rawLaTeXInline
return $ return $ B.rawInline "tex" s
rawConTeXtEnvironment :: PandocMonad m => ParsecT Sources st m Text
rawConTeXtEnvironment :: forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m Text
rawConTeXtEnvironment = ParsecT Sources st m Text -> ParsecT Sources st m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources st m Text -> ParsecT Sources st m Text)
-> ParsecT Sources st m Text -> ParsecT Sources st m Text
forall a b. (a -> b) -> a -> b
$ do
FilePath -> ParsecT Sources st m FilePath
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m FilePath
string FilePath
"\\start"
completion <- ParsecT Sources st m Char -> ParsecT Sources st m Text
forall (m :: * -> *) st.
PandocMonad m =>
ParsecT Sources st m Char -> ParsecT Sources st m Text
inBrackets (ParsecT Sources st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
letter ParsecT Sources st m Char
-> ParsecT Sources st m Char -> ParsecT Sources st m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
digit ParsecT Sources st m Char
-> ParsecT Sources st m Char -> ParsecT Sources st m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources st m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar)
ParsecT Sources st m Text
-> ParsecT Sources st m Text -> ParsecT Sources st m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources st m Char -> ParsecT Sources st m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char ParsecT Sources st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
letter
!contents <- manyTill (rawConTeXtEnvironment <|> countChar 1 anyChar)
(try $ string "\\stop" >> textStr completion)
return $! "\\start" <> completion <> T.concat contents <> "\\stop" <> completion
inBrackets :: PandocMonad m => ParsecT Sources st m Char -> ParsecT Sources st m Text
inBrackets :: forall (m :: * -> *) st.
PandocMonad m =>
ParsecT Sources st m Char -> ParsecT Sources st m Text
inBrackets ParsecT Sources st m Char
parser = do
Char -> ParsecT Sources st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'['
contents <- ParsecT Sources st m Char -> ParsecT Sources st m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
manyChar ParsecT Sources st m Char
parser
char ']'
return $! "[" <> contents <> "]"
spanHtml :: PandocMonad m => MarkdownParser m (F Inlines)
spanHtml :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
spanHtml = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_native_spans
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
(TagOpen _ attrs, _) <- (Tag Text -> Bool)
-> ParsecT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (Tag Text -> Tag Text -> Bool
forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== Text -> [Target] -> Tag Text
forall str. str -> [Attribute str] -> Tag str
TagOpen (Text
"span" :: Text) [])
contents <- mconcat <$> manyTill inline (htmlTag (~== TagClose ("span" :: Text)))
let ident = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"" (Maybe Text -> Text) -> Maybe Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> [Target] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"id" [Target]
attrs
let classes = [Text] -> (Text -> [Text]) -> Maybe Text -> [Text]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] Text -> [Text]
T.words (Maybe Text -> [Text]) -> Maybe Text -> [Text]
forall a b. (a -> b) -> a -> b
$ Text -> [Target] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"class" [Target]
attrs
let keyvals = [(Text
k,Text
v) | (Text
k,Text
v) <- [Target]
attrs, Text
k Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"id" Bool -> Bool -> Bool
&& Text
k Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"class"]
return $ wrapSpan (ident, classes, keyvals) <$> contents
divHtml :: PandocMonad m => MarkdownParser m (F Blocks)
divHtml :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
divHtml = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_native_divs
ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks))
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ do
openpos <- ParsecT Sources ParserState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
(TagOpen _ attrs, _) <- htmlTag (~== TagOpen ("div" :: Text) [])
oldInHtmlBlock <- stateInHtmlBlock <$> getState
updateState $ \ParserState
st -> ParserState
st{ stateInHtmlBlock = Just "div" }
optional blanklines
contents <- mconcat <$>
many (notFollowedBy' (htmlTag (~== TagClose ("div" :: Text)))
>> block)
void (htmlTag (~== TagClose ("div" :: Text))) <|>
(getPosition >>= report . UnclosedDiv openpos)
let ident = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"" (Maybe Text -> Text) -> Maybe Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> [Target] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"id" [Target]
attrs
let classes = [Text] -> (Text -> [Text]) -> Maybe Text -> [Text]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] Text -> [Text]
T.words (Maybe Text -> [Text]) -> Maybe Text -> [Text]
forall a b. (a -> b) -> a -> b
$ Text -> [Target] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"class" [Target]
attrs
let keyvals = [(Text
k,Text
v) | (Text
k,Text
v) <- [Target]
attrs, Text
k Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"id" Bool -> Bool -> Bool
&& Text
k Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"class"]
updateState $ \ParserState
st -> ParserState
st{ stateInHtmlBlock = oldInHtmlBlock }
return $ B.divWith (ident, classes, keyvals) <$> contents
divFenced :: PandocMonad m => MarkdownParser m (F Blocks)
divFenced :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Blocks)
divFenced = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_fenced_divs
ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks))
-> ParsecT Sources ParserState m (Future ParserState Blocks)
-> ParsecT Sources ParserState m (Future ParserState Blocks)
forall a b. (a -> b) -> a -> b
$ do
openpos <- ParsecT Sources ParserState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
string ":::"
skipMany (char ':')
skipMany spaceChar
attribs <- attributes <|> ((\Text
x -> (Text
"",[Text
x],[])) <$> many1Char nonspaceChar)
skipMany spaceChar
skipMany (char ':')
blankline
updateState $ \ParserState
st ->
ParserState
st{ stateFencedDivLevel = stateFencedDivLevel st + 1 }
bs <- mconcat <$> many (notFollowedBy divFenceEnd >> block)
divFenceEnd <|> (getPosition >>= report . UnclosedDiv openpos)
updateState $ \ParserState
st ->
ParserState
st{ stateFencedDivLevel = stateFencedDivLevel st - 1 }
return $ B.divWith attribs <$> bs
divFenceEnd :: PandocMonad m => MarkdownParser m ()
divFenceEnd :: forall (m :: * -> *). PandocMonad m => MarkdownParser m ()
divFenceEnd = ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ do
FilePath -> ParsecT Sources ParserState m 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 m Char
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
':')
ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
blanklines
() -> ParsecT Sources ParserState m ()
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
rawHtmlInline :: PandocMonad m => MarkdownParser m (F Inlines)
rawHtmlInline :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
rawHtmlInline = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_raw_html
inHtmlBlock <- ParserState -> Maybe Text
stateInHtmlBlock (ParserState -> Maybe Text)
-> ParsecT Sources ParserState m ParserState
-> ParsecT Sources ParserState m (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
let isCloseBlockTag Tag str
t = case Maybe Text
inHtmlBlock of
Just Text
t' -> Tag str
t Tag str -> Tag Text -> Bool
forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== Text -> Tag Text
forall str. str -> Tag str
TagClose Text
t'
Maybe Text
Nothing -> Bool
False
mdInHtml <- option False $
( guardEnabled Ext_markdown_in_html_blocks
<|> guardEnabled Ext_markdown_attribute
) >> return True
(_,result) <- htmlTag $ if mdInHtml
then (\Tag Text
x -> Tag Text -> Bool
isInlineTag Tag Text
x Bool -> Bool -> Bool
&&
Bool -> Bool
not (Tag Text -> Bool
forall {str}. StringLike str => Tag str -> Bool
isCloseBlockTag Tag Text
x))
else not . isTextTag
return $ return $ B.rawInline "html" result
emoji :: PandocMonad m => MarkdownParser m (F Inlines)
emoji :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
emoji = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_emoji
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
':'
emojikey <- ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char (ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> FilePath -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
oneOf FilePath
"_+-")
char ':'
case emojiToInline emojikey of
Just Inline
i -> F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$ Inline -> Inlines
forall a. a -> Many a
B.singleton Inline
i)
Maybe Inline
Nothing -> ParsecT Sources ParserState m (F Inlines)
forall a. ParsecT Sources ParserState m a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
cite :: PandocMonad m => MarkdownParser m (F Inlines)
cite :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
cite = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_citations
inNote <- ParserState -> Bool
stateInNote (ParserState -> Bool)
-> ParsecT Sources ParserState m ParserState
-> ParsecT Sources ParserState m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
unless inNote $
updateState $ \ParserState
st -> ParserState
st{ stateNoteNumber = stateNoteNumber st + 1 }
textualCite
<|> do (cs, raw) <- withRaw normalCite
return $ flip B.cite (B.text raw) <$> cs
textualCite :: PandocMonad m => MarkdownParser m (F Inlines)
textualCite :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
textualCite = ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
(suppressAuthor, key) <- Bool -> ParsecT Sources ParserState m (Bool, Text)
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, HasLastStrPosition st) =>
Bool -> ParsecT s st m (Bool, Text)
citeKey Bool
True
getState >>= guard . isNothing . M.lookup key . stateExamples
noteNum <- stateNoteNumber <$> getState
let first = Citation{ citationId :: Text
citationId = Text
key
, citationPrefix :: [Inline]
citationPrefix = []
, citationSuffix :: [Inline]
citationSuffix = []
, citationMode :: CitationMode
citationMode = if Bool
suppressAuthor
then CitationMode
SuppressAuthor
else CitationMode
AuthorInText
, citationNoteNum :: Int
citationNoteNum = Int
noteNum
, citationHash :: Int
citationHash = Int
0
}
(do
(cs, raw) <- withRaw $
(fmap (first:) <$> try (spnl *> normalCite))
<|> bareloc first
let (spaces',raw') = T.span isSpace raw
spc | Text -> Bool
T.null Text
spaces' = Inlines
forall a. Monoid a => a
mempty
| Bool
otherwise = Inlines
B.space
lab <- parseFromString' inlines $ dropBrackets raw'
fallback <- referenceLink B.linkWith (lab,raw')
updateState $ \ParserState
st -> ParserState
st{ stateNoteNumber = noteNum }
return $ do
fallback' <- fallback
cs' <- cs
return $
case B.toList fallback' of
Link{}:[Inline]
_ -> [Citation] -> Inlines -> Inlines
B.cite [Citation
first] (Text -> Inlines
B.str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ Text
"@" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
key) Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
spc Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
fallback'
[Inline]
_ -> [Citation] -> Inlines -> Inlines
B.cite [Citation]
cs' (Text -> Inlines
B.text (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ Text
"@" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
key Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
raw))
<|>
return (do st <- askF
return $ case M.lookup key (stateExamples st) of
Just Int
n -> Text -> Inlines
B.str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ Int -> Text
forall a. Show a => a -> Text
tshow Int
n
Maybe Int
_ -> [Citation] -> Inlines -> Inlines
B.cite [Citation
first] (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ Text
"@" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
key)
bareloc :: PandocMonad m => Citation -> MarkdownParser m (F [Citation])
bareloc :: forall (m :: * -> *).
PandocMonad m =>
Citation -> MarkdownParser m (F [Citation])
bareloc Citation
c = ParsecT Sources ParserState m (F [Citation])
-> ParsecT Sources ParserState m (F [Citation])
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F [Citation])
-> ParsecT Sources ParserState m (F [Citation]))
-> ParsecT Sources ParserState m (F [Citation])
-> ParsecT Sources ParserState m (F [Citation])
forall a b. (a -> b) -> a -> b
$ do
ParsecT Sources ParserState m ()
forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m ()
spnl
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'['
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'^'
suff <- MarkdownParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
suffix
rest <- option (return []) $ try $ char ';' >> spnl >> citeList
spnl
char ']'
notFollowedBy $ oneOf "[("
return $ do
suff' <- suff
rest' <- rest
return $ c{ citationSuffix = B.toList suff' } : rest'
normalCite :: PandocMonad m => MarkdownParser m (F [Citation])
normalCite :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (F [Citation])
normalCite = ParsecT Sources ParserState m (F [Citation])
-> ParsecT Sources ParserState m (F [Citation])
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F [Citation])
-> ParsecT Sources ParserState m (F [Citation]))
-> ParsecT Sources ParserState m (F [Citation])
-> ParsecT Sources ParserState m (F [Citation])
forall a b. (a -> b) -> a -> b
$ do
citations <- ParsecT Sources ParserState m (F [Citation])
-> ParsecT Sources ParserState m (F [Citation])
forall (m :: * -> *) a.
PandocMonad m =>
MarkdownParser m (F a) -> MarkdownParser m (F a)
inBalancedBrackets (ParsecT Sources ParserState m ()
forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m ()
spnl ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F [Citation])
-> ParsecT Sources ParserState m (F [Citation])
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState m (F [Citation])
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (F [Citation])
citeList ParsecT Sources ParserState m (F [Citation])
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F [Citation])
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m ()
forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m ()
spnl)
notFollowedBy (try (void source) <|>
(guardEnabled Ext_bracketed_spans *> void attributes) <|>
void reference)
return citations
suffix :: PandocMonad m => MarkdownParser m (F Inlines)
suffix :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
suffix = ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
hasSpace <- Bool
-> ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
nonspaceChar ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> ParsecT Sources ParserState m Bool
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True)
spnl
ils <- many (notFollowedBy (oneOf ";]") >> inline)
let rest = F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF ([F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat [F Inlines]
ils)
return $ if hasSpace && not (null ils)
then (B.space <>) <$> rest
else rest
prefix :: PandocMonad m => MarkdownParser m (F Inlines)
prefix :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
prefix = F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [F Inlines]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
manyTill (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
';') ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inline) (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']'
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead
(ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b. (a -> b) -> a -> b
$ do ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
';' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m ()
forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m ()
spnl))
Bool -> ParsecT Sources ParserState m (Bool, Text)
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, HasLastStrPosition st) =>
Bool -> ParsecT s st m (Bool, Text)
citeKey Bool
True
Char -> ParsecT Sources ParserState m Char
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Char
']'))
citeList :: PandocMonad m => MarkdownParser m (F [Citation])
citeList :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (F [Citation])
citeList = ([Future ParserState Citation] -> F [Citation])
-> ParsecT Sources ParserState m [Future ParserState Citation]
-> ParsecT Sources ParserState m (F [Citation])
forall a b.
(a -> b)
-> ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Future ParserState Citation] -> F [Citation]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence (ParsecT Sources ParserState m [Future ParserState Citation]
-> ParsecT Sources ParserState m (F [Citation]))
-> ParsecT Sources ParserState m [Future ParserState Citation]
-> ParsecT Sources ParserState m (F [Citation])
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m (Future ParserState Citation)
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m [Future ParserState Citation]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepBy1 ParsecT Sources ParserState m (Future ParserState Citation)
forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Citation)
citation (ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
';' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m ()
forall (m :: * -> *) st. PandocMonad m => ParsecT Sources st m ()
spnl)
citation :: PandocMonad m => MarkdownParser m (F Citation)
citation :: forall (m :: * -> *).
PandocMonad m =>
MarkdownParser m (Future ParserState Citation)
citation = ParsecT Sources ParserState m (Future ParserState Citation)
-> ParsecT Sources ParserState m (Future ParserState Citation)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Future ParserState Citation)
-> ParsecT Sources ParserState m (Future ParserState Citation))
-> ParsecT Sources ParserState m (Future ParserState Citation)
-> ParsecT Sources ParserState m (Future ParserState Citation)
forall a b. (a -> b) -> a -> b
$ do
pref <- MarkdownParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
prefix
(suppress_author, key) <- citeKey True
suff <- suffix
noteNum <- stateNoteNumber <$> getState
return $ do
x <- pref
y <- suff
return Citation{ citationId = key
, citationPrefix = B.toList x
, citationSuffix = B.toList y
, citationMode = if suppress_author
then SuppressAuthor
else NormalCitation
, citationNoteNum = noteNum
, citationHash = 0
}
smart :: PandocMonad m => MarkdownParser m (F Inlines)
smart :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
smart = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_smart
MarkdownParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
doubleQuoted MarkdownParser m (F Inlines)
-> MarkdownParser m (F Inlines) -> MarkdownParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MarkdownParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
singleQuoted MarkdownParser m (F Inlines)
-> MarkdownParser m (F Inlines) -> MarkdownParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines)
-> ParsecT Sources ParserState m Inlines
-> MarkdownParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Inlines
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Inlines
doubleCloseQuote) MarkdownParser m (F Inlines)
-> MarkdownParser m (F Inlines) -> MarkdownParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
(Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines)
-> ParsecT Sources ParserState m Inlines
-> MarkdownParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Inlines
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Inlines
apostrophe) MarkdownParser m (F Inlines)
-> MarkdownParser m (F Inlines) -> MarkdownParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines)
-> ParsecT Sources ParserState m Inlines
-> MarkdownParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Inlines
forall st s (m :: * -> *).
(HasReaderOptions st, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Inlines
dash) MarkdownParser m (F Inlines)
-> MarkdownParser m (F Inlines) -> MarkdownParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines)
-> ParsecT Sources ParserState m Inlines
-> MarkdownParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Inlines
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Inlines
ellipses)
singleQuoted :: PandocMonad m => MarkdownParser m (F Inlines)
singleQuoted :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
singleQuoted = do
ParsecT Sources ParserState m ()
forall st (m :: * -> *) s.
(HasLastStrPosition st, HasQuoteContext st m, Stream s m Char,
UpdateSourcePos s Char) =>
ParsecT s st m ()
singleQuoteStart
(ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (QuoteContext
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s a.
QuoteContext
-> ParsecT s ParserState m a -> ParsecT s ParserState m a
forall st (m :: * -> *) s a.
HasQuoteContext st m =>
QuoteContext -> ParsecT s st m a -> ParsecT s st m a
withQuoteContext QuoteContext
InSingleQuote (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$
(Inlines -> Inlines) -> F Inlines -> F Inlines
forall a b.
(a -> b) -> Future ParserState a -> Future ParserState b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.singleQuoted (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m [F Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
many1Till ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inline ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
singleQuoteEnd))
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Inlines
B.str Text
"\8217")))
doubleQuoted :: PandocMonad m => MarkdownParser m (F Inlines)
doubleQuoted :: forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
doubleQuoted = do
ParsecT Sources ParserState m ()
forall st (m :: * -> *) s.
(HasLastStrPosition st, HasQuoteContext st m, Stream s m Char,
UpdateSourcePos s Char) =>
ParsecT s st m ()
doubleQuoteStart
(ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (QuoteContext
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s a.
QuoteContext
-> ParsecT s ParserState m a -> ParsecT s ParserState m a
forall st (m :: * -> *) s a.
HasQuoteContext st m =>
QuoteContext -> ParsecT s st m a -> ParsecT s st m a
withQuoteContext QuoteContext
InDoubleQuote (ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines))
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall a b. (a -> b) -> a -> b
$
(Inlines -> Inlines) -> F Inlines -> F Inlines
forall a b.
(a -> b) -> Future ParserState a -> Future ParserState b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.doubleQuoted (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Sources ParserState m [F Inlines]
-> ParsecT Sources ParserState m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m [F Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
many1Till ParsecT Sources ParserState m (F Inlines)
forall (m :: * -> *). PandocMonad m => MarkdownParser m (F Inlines)
inline ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
doubleQuoteEnd))
ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
-> ParsecT Sources ParserState m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (F Inlines -> ParsecT Sources ParserState m (F Inlines)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines
forall a. a -> Future ParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Inlines
B.str Text
"\8220")))