{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ViewPatterns #-}
module Text.Pandoc.Readers.DokuWiki (readDokuWiki) where
import Control.Monad
import Control.Monad.Except (throwError)
import Data.Char (isAlphaNum, isDigit)
import qualified Data.Foldable as F
import Data.Maybe (fromMaybe, catMaybes)
import Data.Bifunctor (second)
import Data.Text (Text)
import qualified Data.Text as T
import qualified Text.Pandoc.Builder as B
import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
import Text.Pandoc.Definition
import Text.Pandoc.Options
import Text.Pandoc.Parsing hiding (enclosed)
import Text.Pandoc.Shared (trim, stringify, tshow)
import Data.List (isPrefixOf, isSuffixOf)
import qualified Safe
readDokuWiki :: (PandocMonad m, ToSources a)
=> ReaderOptions
-> a
-> m Pandoc
readDokuWiki :: forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> a -> m Pandoc
readDokuWiki ReaderOptions
opts a
s = do
let sources :: Sources
sources = forall a. ToSources a => a -> Sources
toSources a
s
Either ParseError Pandoc
res <- forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a)
runParserT forall (m :: * -> *). PandocMonad m => DWParser m Pandoc
parseDokuWiki forall a. Default a => a
def {stateOptions :: ReaderOptions
stateOptions = ReaderOptions
opts }
(Sources -> SourceName
initialSourceName Sources
sources) Sources
sources
case Either ParseError Pandoc
res of
Left ParseError
e -> forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall a b. (a -> b) -> a -> b
$ Sources -> ParseError -> PandocError
fromParsecError Sources
sources ParseError
e
Right Pandoc
d -> forall (m :: * -> *) a. Monad m => a -> m a
return Pandoc
d
type DWParser = ParsecT Sources ParserState
eol :: (Stream s m Char, UpdateSourcePos s Char) => ParsecT s st m ()
eol :: forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
eol = forall (f :: * -> *) a. Functor f => f a -> f ()
void forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
guardColumnOne :: PandocMonad m => DWParser m ()
guardColumnOne :: forall (m :: * -> *). PandocMonad m => DWParser m ()
guardColumnOne = forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \SourcePos
pos -> forall (f :: * -> *). Alternative f => Bool -> f ()
guard (SourcePos -> Column
sourceColumn SourcePos
pos forall a. Eq a => a -> a -> Bool
== Column
1)
parseDokuWiki :: PandocMonad m => DWParser m Pandoc
parseDokuWiki :: forall (m :: * -> *). PandocMonad m => DWParser m Pandoc
parseDokuWiki =
Blocks -> Pandoc
B.doc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall (m :: * -> *). PandocMonad m => DWParser m Blocks
block forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
codeLanguage :: PandocMonad m => DWParser m (Text, [Text], [(Text, Text)])
codeLanguage :: forall (m :: * -> *).
PandocMonad m =>
DWParser m (Text, [Text], [(Text, Text)])
codeLanguage = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
Text
rawLang <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"-" (forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'>')))
let attr :: [Text]
attr = case Text
rawLang of
Text
"-" -> []
Text
l -> [Text
l]
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
"", [Text]
attr, [])
codeTag :: PandocMonad m
=> ((Text, [Text], [(Text, Text)]) -> Text -> a)
-> Text
-> DWParser m a
codeTag :: forall (m :: * -> *) a.
PandocMonad m =>
((Text, [Text], [(Text, Text)]) -> Text -> a)
-> Text -> DWParser m a
codeTag (Text, [Text], [(Text, Text)]) -> Text -> a
f Text
tag = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ (Text, [Text], [(Text, Text)]) -> Text -> a
f
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'<'
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
tag
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (m :: * -> *).
PandocMonad m =>
DWParser m (Text, [Text], [(Text, Text)])
codeLanguage
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'>')
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
eol)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"</" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
tag forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'>')
inline' :: PandocMonad m => DWParser m B.Inlines
inline' :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline' = forall (m :: * -> *). PandocMonad m => DWParser m Inlines
whitespace
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline''
inline'' :: PandocMonad m => DWParser m B.Inlines
inline'' :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline'' = forall (m :: * -> *). PandocMonad m => DWParser m Inlines
br
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
bold
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
italic
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
underlined
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
nowiki
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
percent
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
link
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
image
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
monospaced
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
subscript
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
superscript
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
deleted
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
footnote
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inlineCode
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inlineFile
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inlineRaw
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
math
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
autoLink
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
autoEmail
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
notoc
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
nocache
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
str
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
symbol
forall s u (m :: * -> *) a.
ParsecT s u m a -> SourceName -> ParsecT s u m a
<?> SourceName
"inline"
inlineUnconsolidatedWhitespace :: PandocMonad m => DWParser m B.Inlines
inlineUnconsolidatedWhitespace :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inlineUnconsolidatedWhitespace = (Inlines
B.space forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar) forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline'
inline :: PandocMonad m => DWParser m B.Inlines
inline :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline = forall (m :: * -> *). PandocMonad m => DWParser m Inlines
endline forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline'
endline :: PandocMonad m => DWParser m B.Inlines
endline :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
endline = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Inlines
B.softbreak forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). PandocMonad m => DWParser m Inlines
linebreak
whitespace :: PandocMonad m => DWParser m B.Inlines
whitespace :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
whitespace = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Inlines
B.space forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
br :: PandocMonad m => DWParser m B.Inlines
br :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
br = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Inlines
B.linebreak forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"\\\\" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
space
linebreak :: PandocMonad m => DWParser m B.Inlines
linebreak :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
linebreak = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (forall {u}. ParsecT Sources u m Inlines
lastNewline 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
innerNewline)
where lastNewline :: ParsecT Sources u m Inlines
lastNewline = forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
innerNewline :: ParsecT Sources ParserState m Inlines
innerNewline = forall (f :: * -> *) a. Applicative f => a -> f a
pure Inlines
B.space
between :: (Monoid c, PandocMonad m, Show b)
=> DWParser m a -> DWParser m b -> (DWParser m b -> DWParser m c)
-> DWParser m c
between :: forall c (m :: * -> *) b a.
(Monoid c, PandocMonad m, Show b) =>
DWParser m a
-> DWParser m b -> (DWParser m b -> DWParser m c) -> DWParser m c
between DWParser m a
start DWParser m b
end DWParser m b -> DWParser m c
p =
forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m a
start forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy forall (m :: * -> *). PandocMonad m => DWParser m Inlines
whitespace forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> 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 (DWParser m b -> DWParser m c
p DWParser m b
end) DWParser m b
end)
enclosed :: (Monoid b, PandocMonad m, Show a)
=> DWParser m a -> (DWParser m a -> DWParser m b) -> DWParser m b
enclosed :: forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
DWParser m a -> (DWParser m a -> DWParser m b) -> DWParser m b
enclosed DWParser m a
sep DWParser m a -> DWParser m b
p = forall c (m :: * -> *) b a.
(Monoid c, PandocMonad m, Show b) =>
DWParser m a
-> DWParser m b -> (DWParser m b -> DWParser m c) -> DWParser m c
between DWParser m a
sep (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try DWParser m a
sep) DWParser m a -> DWParser m b
p
nestedInlines :: (Show a, PandocMonad m)
=> DWParser m a -> DWParser m B.Inlines
nestedInlines :: forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Inlines
nestedInlines DWParser m a
end = ParsecT Sources ParserState m Inlines
innerSpace 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
nestedInline
where
innerSpace :: ParsecT Sources ParserState m Inlines
innerSpace = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => DWParser m Inlines
whitespace forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy DWParser m a
end
nestedInline :: ParsecT Sources ParserState m Inlines
nestedInline = forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy forall (m :: * -> *). PandocMonad m => DWParser m Inlines
whitespace forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline
bold :: PandocMonad m => DWParser m B.Inlines
bold :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
bold = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.strong forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
DWParser m a -> (DWParser m a -> DWParser m b) -> DWParser m b
enclosed (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"**") forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Inlines
nestedInlines
italic :: PandocMonad m => DWParser m B.Inlines
italic :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
italic = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.emph forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
DWParser m a -> (DWParser m a -> DWParser m b) -> DWParser m b
enclosed (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"//") forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Inlines
nestedInlines
underlined :: PandocMonad m => DWParser m B.Inlines
underlined :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
underlined = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.underline forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
DWParser m a -> (DWParser m a -> DWParser m b) -> DWParser m b
enclosed (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"__") forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Inlines
nestedInlines
nowiki :: PandocMonad m => DWParser m B.Inlines
nowiki :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
nowiki = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.text forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"<nowiki>" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"</nowiki>")
percent :: PandocMonad m => DWParser m B.Inlines
percent :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
percent = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.text forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
DWParser m a -> (DWParser m a -> DWParser m b) -> DWParser m b
enclosed (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"%%") forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Text
nestedText
nestedText :: (Show a, PandocMonad m)
=> DWParser m a -> DWParser m Text
nestedText :: forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Text
nestedText DWParser m a
end = ParsecT Sources ParserState m Text
innerSpace forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Column -> ParsecT s st m Char -> ParsecT s st m Text
countChar Column
1 forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
nonspaceChar
where
innerSpace :: ParsecT Sources ParserState m Text
innerSpace = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy DWParser m a
end
monospaced :: PandocMonad m => DWParser m B.Inlines
monospaced :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
monospaced = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.code forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Text] -> Text
T.concat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a. Walkable Inline a => a -> Text
stringify forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Many a -> [a]
B.toList) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
DWParser m a -> (DWParser m a -> DWParser m b) -> DWParser m b
enclosed (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"''") forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Inlines
nestedInlines
subscript :: PandocMonad m => DWParser m B.Inlines
subscript :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
subscript = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.subscript forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall c (m :: * -> *) b a.
(Monoid c, PandocMonad m, Show b) =>
DWParser m a
-> DWParser m b -> (DWParser m b -> DWParser m c) -> DWParser m c
between (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"<sub>") (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"</sub>") forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Inlines
nestedInlines
superscript :: PandocMonad m => DWParser m B.Inlines
superscript :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
superscript = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.superscript forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall c (m :: * -> *) b a.
(Monoid c, PandocMonad m, Show b) =>
DWParser m a
-> DWParser m b -> (DWParser m b -> DWParser m c) -> DWParser m c
between (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"<sup>") (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"</sup>") forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Inlines
nestedInlines
deleted :: PandocMonad m => DWParser m B.Inlines
deleted :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
deleted = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.strikeout forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall c (m :: * -> *) b a.
(Monoid c, PandocMonad m, Show b) =>
DWParser m a
-> DWParser m b -> (DWParser m b -> DWParser m c) -> DWParser m c
between (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"<del>") (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"</del>") forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Inlines
nestedInlines
footnote :: PandocMonad m => DWParser m B.Inlines
= forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Blocks -> Inlines
B.note forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Blocks
B.para forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall c (m :: * -> *) b a.
(Monoid c, PandocMonad m, Show b) =>
DWParser m a
-> DWParser m b -> (DWParser m b -> DWParser m c) -> DWParser m c
between (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"((") (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"))") forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Inlines
nestedInlines
inlineCode :: PandocMonad m => DWParser m B.Inlines
inlineCode :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inlineCode = forall (m :: * -> *) a.
PandocMonad m =>
((Text, [Text], [(Text, Text)]) -> Text -> a)
-> Text -> DWParser m a
codeTag (Text, [Text], [(Text, Text)]) -> Text -> Inlines
B.codeWith Text
"code"
inlineFile :: PandocMonad m => DWParser m B.Inlines
inlineFile :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inlineFile = forall (m :: * -> *) a.
PandocMonad m =>
((Text, [Text], [(Text, Text)]) -> Text -> a)
-> Text -> DWParser m a
codeTag (Text, [Text], [(Text, Text)]) -> Text -> Inlines
B.codeWith Text
"file"
inlineRaw :: PandocMonad m => DWParser m B.Inlines
inlineRaw :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inlineRaw = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'<'
Text
fmt <- forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
[Text] -> ParsecT s st m Text
oneOfStrings [Text
"html", Text
"php", Text
"latex"]
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'>'
Text
contents <- forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar
(forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"</" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string (Text -> SourceName
T.unpack Text
fmt) forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'>')
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
case Text -> Text
T.toLower Text
fmt of
Text
"php" -> Text -> Text -> Inlines
B.rawInline Text
"html" forall a b. (a -> b) -> a -> b
$ Text
"<?php " forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
" ?>"
Text
f -> Text -> Text -> Inlines
B.rawInline Text
f Text
contents
math :: PandocMonad m => DWParser m B.Inlines
math :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
math = (Text -> Inlines
B.displayMath forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall st s (m :: * -> *).
(HasReaderOptions st, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
mathDisplay) forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Text -> Inlines
B.math forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall st s (m :: * -> *).
(HasReaderOptions st, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
mathInline)
makeLink :: (Text, Text) -> B.Inlines
makeLink :: (Text, Text) -> Inlines
makeLink (Text
text, Text
url) = Text -> Text -> Inlines -> Inlines
B.link Text
url Text
"" forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
text
autoEmail :: PandocMonad m => DWParser m B.Inlines
autoEmail :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
autoEmail = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
ParserState
state <- forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ ParserState -> Bool
stateAllowLinks ParserState
state
(Text, Text) -> Inlines
makeLink forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'<' forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (Text, Text)
emailAddress forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'>'
autoLink :: PandocMonad m => DWParser m B.Inlines
autoLink :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
autoLink = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
ParserState
state <- forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ ParserState -> Bool
stateAllowLinks ParserState
state
(Text
text, Text
url) <- forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (Text, Text)
uri
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ Char -> Bool
checkLink (Text -> Char
T.last Text
url)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ (Text, Text) -> Inlines
makeLink (Text
text, Text
url)
where
checkLink :: Char -> Bool
checkLink Char
c
| Char
c forall a. Eq a => a -> a -> Bool
== Char
'/' = Bool
True
| Bool
otherwise = Char -> Bool
isAlphaNum Char
c
notoc :: PandocMonad m => DWParser m B.Inlines
notoc :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
notoc = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"~~NOTOC~~"
nocache :: PandocMonad m => DWParser m B.Inlines
nocache :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
nocache = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"~~NOCACHE~~"
str :: PandocMonad m => DWParser m B.Inlines
str :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
str = Text -> Inlines
B.str forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
characterReference)
symbol :: PandocMonad m => DWParser m B.Inlines
symbol :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
symbol = Text -> Inlines
B.str forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Column -> ParsecT s st m Char -> ParsecT s st m Text
countChar Column
1 forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
nonspaceChar
link :: PandocMonad m => DWParser m B.Inlines
link :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
link = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
ParserState
st <- forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ ParserState -> Bool
stateAllowLinks ParserState
st
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState forall a b. (a -> b) -> a -> b
$ ParserState
st{ stateAllowLinks :: Bool
stateAllowLinks = Bool
False }
Inlines
l <- forall (m :: * -> *). PandocMonad m => DWParser m Inlines
linkText
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState forall a b. (a -> b) -> a -> b
$ ParserState
st{ stateAllowLinks :: Bool
stateAllowLinks = Bool
True }
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
l
isExternalLink :: Text -> Bool
isExternalLink :: Text -> Bool
isExternalLink Text
s = Text
"://" Text -> Text -> Bool
`T.isPrefixOf` Text
sSuff
where
sSuff :: Text
sSuff = (Char -> Bool) -> Text -> Text
T.dropWhile (\Char
c -> Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| (Char
c forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char
'-', Char
'.', Char
'+'])) Text
s
isAbsolutePath :: Text -> Bool
isAbsolutePath :: Text -> Bool
isAbsolutePath (Text -> Maybe (Char, Text)
T.uncons -> Just (Char
'.', Text
_)) = Bool
False
isAbsolutePath Text
s = (Char -> Bool) -> Text -> Bool
T.any (forall a. Eq a => a -> a -> Bool
== Char
':') Text
s
normalizeDots :: Text -> Text
normalizeDots :: Text -> Text
normalizeDots Text
path
| Bool -> Bool
not (Text -> Bool
T.null Text
pref) = case Text -> Maybe (Char, Text)
T.uncons Text
suff of
Just (Char
':', Text
_) -> Text
path
Maybe (Char, Text)
_ -> Text
pref forall a. Semigroup a => a -> a -> a
<> Text
":" forall a. Semigroup a => a -> a -> a
<> Text
suff
| Bool
otherwise = Text
path
where
(Text
pref, Text
suff) = (Char -> Bool) -> Text -> (Text, Text)
T.span (forall a. Eq a => a -> a -> Bool
== Char
'.') Text
path
normalizeInternalPath :: Text -> Text
normalizeInternalPath :: Text -> Text
normalizeInternalPath Text
path =
if Text -> Bool
isAbsolutePath Text
path
then Text -> Text
ensureAbsolute Text
normalizedPath
else Text
normalizedPath
where
normalizedPath :: Text
normalizedPath = Text -> [Text] -> Text
T.intercalate Text
"/" forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
dropWhile (forall a. Eq a => a -> a -> Bool
== Text
".") forall a b. (a -> b) -> a -> b
$ Text -> Text -> [Text]
T.splitOn Text
":" forall a b. (a -> b) -> a -> b
$ Text -> Text
normalizeDots Text
path
ensureAbsolute :: Text -> Text
ensureAbsolute s :: Text
s@(Text -> Maybe (Char, Text)
T.uncons -> Just (Char
'/', Text
_)) = Text
s
ensureAbsolute Text
s = Text
"/" forall a. Semigroup a => a -> a -> a
<> Text
s
normalizePath :: Text -> Text
normalizePath :: Text -> Text
normalizePath Text
path =
if Text -> Bool
isExternalLink Text
path
then Text
path
else Text -> Text
normalizeInternalPath Text
path
urlToText :: Text -> Text
urlToText :: Text -> Text
urlToText Text
url =
if Text -> Bool
isExternalLink Text
url
then Text
url
else (Char -> Bool) -> Text -> Text
T.takeWhileEnd (forall a. Eq a => a -> a -> Bool
/= Char
':') Text
url
parseLink :: PandocMonad m
=> (Text -> Maybe B.Inlines -> B.Inlines)
-> Text
-> Text
-> DWParser m B.Inlines
parseLink :: forall (m :: * -> *).
PandocMonad m =>
(Text -> Maybe Inlines -> Inlines)
-> Text -> Text -> DWParser m Inlines
parseLink Text -> Maybe Inlines -> Inlines
f Text
l Text
r = Text -> Maybe Inlines -> Inlines
f
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
l
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> 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 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (forall (f :: * -> *) a. Functor f => f a -> f ()
void (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|') forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
r)))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (Inlines -> Inlines
B.trimInlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
r)))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
r
splitInterwiki :: Text -> Maybe (Text, Text)
splitInterwiki :: Text -> Maybe (Text, Text)
splitInterwiki Text
path =
case (Char -> Bool) -> Text -> (Text, Text)
T.span (\Char
c -> Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'.') Text
path of
(Text
l, Text -> Maybe (Char, Text)
T.uncons -> Just (Char
'>', Text
r)) -> forall a. a -> Maybe a
Just (Text
l, Text
r)
(Text, Text)
_ -> forall a. Maybe a
Nothing
interwikiToUrl :: Text -> Text -> Text
interwikiToUrl :: Text -> Text -> Text
interwikiToUrl Text
"callto" Text
page = Text
"callto://" forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"doku" Text
page = Text
"https://www.dokuwiki.org/" forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"phpfn" Text
page = Text
"https://secure.php.net/" forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"tel" Text
page = Text
"tel:" forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"wp" Text
page = Text
"https://en.wikipedia.org/wiki/" forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"wpde" Text
page = Text
"https://de.wikipedia.org/wiki/" forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"wpes" Text
page = Text
"https://es.wikipedia.org/wiki/" forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"wpfr" Text
page = Text
"https://fr.wikipedia.org/wiki/" forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"wpjp" Text
page = Text
"https://jp.wikipedia.org/wiki/" forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"wppl" Text
page = Text
"https://pl.wikipedia.org/wiki/" forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
unknown Text
page = Text
unknown forall a. Semigroup a => a -> a -> a
<> Text
">" forall a. Semigroup a => a -> a -> a
<> Text
page
linkText :: PandocMonad m => DWParser m B.Inlines
linkText :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
linkText = forall (m :: * -> *).
PandocMonad m =>
(Text -> Maybe Inlines -> Inlines)
-> Text -> Text -> DWParser m Inlines
parseLink Text -> Maybe Inlines -> Inlines
fromRaw Text
"[[" Text
"]]"
where
fromRaw :: Text -> Maybe Inlines -> Inlines
fromRaw Text
path Maybe Inlines
description =
Text -> Text -> Inlines -> Inlines
B.link Text
normalizedPath Text
"" (forall a. a -> Maybe a -> a
fromMaybe (Text -> Inlines
B.str Text
defaultDescription) Maybe Inlines
description)
where
path' :: Text
path' = Text -> Text
trim Text
path
interwiki :: Maybe (Text, Text)
interwiki = Text -> Maybe (Text, Text)
splitInterwiki Text
path'
normalizedPath :: Text
normalizedPath =
case Maybe (Text, Text)
interwiki of
Maybe (Text, Text)
Nothing -> Text -> Text
normalizePath Text
path'
Just (Text
l, Text
r) -> Text -> Text -> Text
interwikiToUrl Text
l Text
r
defaultDescription :: Text
defaultDescription =
case Maybe (Text, Text)
interwiki of
Maybe (Text, Text)
Nothing -> Text -> Text
urlToText Text
path'
Just (Text
_, Text
r) -> Text
r
isWidthHeightParameter :: Text -> Bool
isWidthHeightParameter :: Text -> Bool
isWidthHeightParameter Text
s =
case Text -> Maybe (Char, Text)
T.uncons Text
s of
Just (Char
x, Text
xs) ->
Char -> Bool
isDigit Char
x Bool -> Bool -> Bool
&& case Text -> Maybe (Char, Text)
T.uncons forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Text
T.dropWhile Char -> Bool
isDigit Text
xs of
Just (Char
'x', Text
ys) | Bool -> Bool
not (Text -> Bool
T.null Text
ys) -> (Char -> Bool) -> Text -> Bool
T.all Char -> Bool
isDigit Text
ys
Maybe (Char, Text)
Nothing -> Bool
True
Maybe (Char, Text)
_ -> Bool
False
Maybe (Char, Text)
_ -> Bool
False
parseWidthHeight :: Text -> (Maybe Text, Maybe Text)
parseWidthHeight :: Text -> (Maybe Text, Maybe Text)
parseWidthHeight Text
s = (Maybe Text
width, Maybe Text
height)
where
width :: Maybe Text
width = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Text
T.takeWhile Char -> Bool
isDigit Text
s
height :: Maybe Text
height =
case Text -> Maybe (Char, Text)
T.uncons forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Text
T.dropWhile Char -> Bool
isDigit Text
s of
Just (Char
'x', Text
xs) -> forall a. a -> Maybe a
Just Text
xs
Maybe (Char, Text)
_ -> forall a. Maybe a
Nothing
image :: PandocMonad m => DWParser m B.Inlines
image :: forall (m :: * -> *). PandocMonad m => DWParser m Inlines
image = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
PandocMonad m =>
(Text -> Maybe Inlines -> Inlines)
-> Text -> Text -> DWParser m Inlines
parseLink Text -> Maybe Inlines -> Inlines
fromRaw Text
"{{" Text
"}}"
where
fromRaw :: Text -> Maybe Inlines -> Inlines
fromRaw Text
path Maybe Inlines
description =
if Bool
linkOnly
then Text -> Text -> Inlines -> Inlines
B.link Text
normalizedPath Text
"" (forall a. a -> Maybe a -> a
fromMaybe Inlines
defaultDescription Maybe Inlines
description)
else (Text, [Text], [(Text, Text)])
-> Text -> Text -> Inlines -> Inlines
B.imageWith (Text
"", [Text]
classes, [(Text, Text)]
attributes) Text
normalizedPath Text
"" (forall a. a -> Maybe a -> a
fromMaybe Inlines
defaultDescription Maybe Inlines
description)
where
(Text
path', Text
parameters) = (Char -> Bool) -> Text -> (Text, Text)
T.span (forall a. Eq a => a -> a -> Bool
/= Char
'?') forall a b. (a -> b) -> a -> b
$ Text -> Text
trim Text
path
normalizedPath :: Text
normalizedPath = Text -> Text
normalizePath Text
path'
leftPadding :: Bool
leftPadding = Text
" " Text -> Text -> Bool
`T.isPrefixOf` Text
path
rightPadding :: Bool
rightPadding = Text
" " Text -> Text -> Bool
`T.isSuffixOf` Text
path
classes :: [Text]
classes =
case (Bool
leftPadding, Bool
rightPadding) of
(Bool
False, Bool
False) -> []
(Bool
False, Bool
True) -> [Text
"align-left"]
(Bool
True, Bool
False) -> [Text
"align-right"]
(Bool
True, Bool
True) -> [Text
"align-center"]
parameterList :: [Text]
parameterList = Text -> Text -> [Text]
T.splitOn Text
"&" forall a b. (a -> b) -> a -> b
$ Column -> Text -> Text
T.drop Column
1 Text
parameters
linkOnly :: Bool
linkOnly = Text
"linkonly" forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text]
parameterList
(Maybe Text
width, Maybe Text
height) = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a. Maybe a
Nothing, forall a. Maybe a
Nothing) Text -> (Maybe Text, Maybe Text)
parseWidthHeight (forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
F.find Text -> Bool
isWidthHeightParameter [Text]
parameterList)
attributes :: [(Text, Text)]
attributes = forall a. [Maybe a] -> [a]
catMaybes [
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text
"width",) Maybe Text
width,
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text
"height",) Maybe Text
height,
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text
"query",) (if Text -> Bool
T.null Text
parameters then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just Text
parameters)
]
defaultDescription :: Inlines
defaultDescription = Text -> Inlines
B.str forall a b. (a -> b) -> a -> b
$ Text -> Text
urlToText Text
path'
block :: PandocMonad m => DWParser m B.Blocks
block :: forall (m :: * -> *). PandocMonad m => DWParser m Blocks
block = do
Blocks
res <- forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Blocks
blockElements
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Blocks
para
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
forall (m :: * -> *). PandocMonad m => Text -> m ()
trace (Column -> Text -> Text
T.take Column
60 forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> Text
tshow forall a b. (a -> b) -> a -> b
$ forall a. Many a -> [a]
B.toList Blocks
res)
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
res
blockElements :: PandocMonad m => DWParser m B.Blocks
blockElements :: forall (m :: * -> *). PandocMonad m => DWParser m Blocks
blockElements = forall (m :: * -> *). PandocMonad m => DWParser m Blocks
horizontalLine
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Blocks
header
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => Text -> DWParser m Blocks
list Text
" "
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Blocks
indentedCode
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Blocks
quote
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Blocks
blockCode
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Blocks
blockFile
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Blocks
blockRaw
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => DWParser m Blocks
table
horizontalLine :: PandocMonad m => DWParser m B.Blocks
horizontalLine :: forall (m :: * -> *). PandocMonad m => DWParser m Blocks
horizontalLine = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Blocks
B.horizontalRule forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"---" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'-') forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
eol
header :: PandocMonad m => DWParser m B.Blocks
= forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *). PandocMonad m => DWParser m ()
guardColumnOne
SourceName
eqs <- forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'=')
let lev :: Column
lev = forall (t :: * -> *) a. Foldable t => t a -> Column
length SourceName
eqs
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ Column
lev forall a. Ord a => a -> a -> Bool
< Column
7
Inlines
contents <- Inlines -> Inlines
B.trimInlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'=' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'='))
(Text, [Text], [(Text, Text)])
attr <- forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st, HasLogMessages st,
HasIdentifierList st) =>
(Text, [Text], [(Text, Text)])
-> Inlines -> ParsecT s st m (Text, [Text], [(Text, Text)])
registerHeader (Text, [Text], [(Text, Text)])
nullAttr Inlines
contents
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ (Text, [Text], [(Text, Text)]) -> Column -> Inlines -> Blocks
B.headerWith (Text, [Text], [(Text, Text)])
attr (Column
7 forall a. Num a => a -> a -> a
- Column
lev) Inlines
contents
list :: PandocMonad m => Text -> DWParser m B.Blocks
list :: forall (m :: * -> *). PandocMonad m => Text -> DWParser m Blocks
list Text
prefix = forall (m :: * -> *). PandocMonad m => Text -> DWParser m Blocks
bulletList Text
prefix forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => Text -> DWParser m Blocks
orderedList Text
prefix
bulletList :: PandocMonad m => Text -> DWParser m B.Blocks
bulletList :: forall (m :: * -> *). PandocMonad m => Text -> DWParser m Blocks
bulletList Text
prefix = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ [Blocks] -> Blocks
B.bulletList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
PandocMonad m =>
Text -> Char -> DWParser m [Blocks]
parseList Text
prefix Char
'*'
orderedList :: PandocMonad m => Text -> DWParser m B.Blocks
orderedList :: forall (m :: * -> *). PandocMonad m => Text -> DWParser m Blocks
orderedList Text
prefix = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ [Blocks] -> Blocks
B.orderedList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
PandocMonad m =>
Text -> Char -> DWParser m [Blocks]
parseList Text
prefix Char
'-'
parseList :: PandocMonad m
=> Text
-> Char
-> DWParser m [B.Blocks]
parseList :: forall (m :: * -> *).
PandocMonad m =>
Text -> Char -> DWParser m [Blocks]
parseList Text
prefix Char
marker =
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall a. Semigroup a => a -> a -> a
(<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Blocks
item forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Monoid a => [a] -> a
mconcat (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Sources ParserState m Blocks
continuation))
where
continuation :: ParsecT Sources ParserState m Blocks
continuation = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => Text -> DWParser m Blocks
list (Text
" " forall a. Semigroup a => a -> a -> a
<> Text
prefix)
item :: ParsecT Sources ParserState m Blocks
item = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
prefix forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
marker forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
' ' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState m Blocks
itemContents
itemContents :: ParsecT Sources ParserState m Blocks
itemContents = Inlines -> Blocks
B.plain forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall 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 forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline' forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
eol
indentedCode :: PandocMonad m => DWParser m B.Blocks
indentedCode :: forall (m :: * -> *). PandocMonad m => DWParser m Blocks
indentedCode = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Text -> Blocks
B.codeBlock forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Text
T.unlines forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall {u}. ParsecT Sources u m Text
indentedLine
where
indentedLine :: ParsecT Sources u m Text
indentedLine = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
" " forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
eol
quote :: PandocMonad m => DWParser m B.Blocks
quote :: forall (m :: * -> *). PandocMonad m => DWParser m Blocks
quote = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Column -> ParsecT Sources ParserState m Blocks
nestedQuote Column
0
where
prefix :: Column -> ParsecT s u m SourceName
prefix Column
level = forall s (m :: * -> *) t u a.
Stream s m t =>
Column -> ParsecT s u m a -> ParsecT s u m [a]
count Column
level (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'>')
contents :: Column -> ParsecT Sources ParserState m Blocks
contents Column
level = Column -> ParsecT Sources ParserState m Blocks
nestedQuote Column
level forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Blocks
quoteLine
quoteLine :: ParsecT Sources ParserState m Blocks
quoteLine = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
B.plain forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
B.trimInlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall 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 forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline' forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
eol
quoteContents :: Column -> ParsecT Sources ParserState m Blocks
quoteContents Column
level = forall a. Semigroup a => a -> a -> a
(<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Column -> ParsecT Sources ParserState m Blocks
contents Column
level forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Column -> ParsecT Sources ParserState m Blocks
quoteContinuation Column
level
quoteContinuation :: Column -> ParsecT Sources ParserState m Blocks
quoteContinuation Column
level = forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall {s} {m :: * -> *} {u}.
(Stream s m Char, UpdateSourcePos s Char) =>
Column -> ParsecT s u m SourceName
prefix Column
level forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Column -> ParsecT Sources ParserState m Blocks
contents Column
level)
nestedQuote :: Column -> ParsecT Sources ParserState m Blocks
nestedQuote Column
level = Blocks -> Blocks
B.blockQuote forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'>' forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Column -> ParsecT Sources ParserState m Blocks
quoteContents (Column
level forall a. Num a => a -> a -> a
+ Column
1 :: Int)
blockRaw :: PandocMonad m => DWParser m B.Blocks
blockRaw :: forall (m :: * -> *). PandocMonad m => DWParser m Blocks
blockRaw = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'<'
Text
fmt <- forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
[Text] -> ParsecT s st m Text
oneOfStrings [Text
"HTML", Text
"PHP", Text
"LATEX"]
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'>'
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
eol)
Text
contents <- forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar
(forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string SourceName
"</" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string (Text -> SourceName
T.unpack Text
fmt) forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'>')
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
case Text -> Text
T.toLower Text
fmt of
Text
"php" -> Text -> Text -> Blocks
B.rawBlock Text
"html" forall a b. (a -> b) -> a -> b
$ Text
"<?php " forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
" ?>"
Text
f -> Text -> Text -> Blocks
B.rawBlock Text
f Text
contents
table :: PandocMonad m => DWParser m B.Blocks
table :: forall (m :: * -> *). PandocMonad m => DWParser m Blocks
table = do
Char
firstSeparator <- forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall (m :: * -> *). PandocMonad m => DWParser m Char
tableCellSeparator
[[(Alignment, Blocks)]]
rows <- forall (m :: * -> *).
PandocMonad m =>
DWParser m [[(Alignment, Blocks)]]
tableRows
let firstRow :: [(Alignment, Blocks)]
firstRow = forall a. a -> Maybe a -> a
fromMaybe [] forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> Maybe a
Safe.headMay forall a b. (a -> b) -> a -> b
$ [[(Alignment, Blocks)]]
rows
let ([(Alignment, Blocks)]
headerRow, [[(Alignment, Blocks)]]
body) = if Char
firstSeparator forall a. Eq a => a -> a -> Bool
== Char
'^'
then ([(Alignment, Blocks)]
firstRow, forall a. [a] -> [a]
tail [[(Alignment, Blocks)]]
rows)
else ([], [[(Alignment, Blocks)]]
rows)
let attrs :: [(Alignment, ColWidth)]
attrs = forall a b. (a -> b) -> [a] -> [b]
map (\(Alignment
a, Blocks
_) -> (Alignment
a, ColWidth
ColWidthDefault)) [(Alignment, Blocks)]
firstRow
let toRow :: [Blocks] -> Row
toRow = (Text, [Text], [(Text, Text)]) -> [Cell] -> Row
Row (Text, [Text], [(Text, Text)])
nullAttr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map Blocks -> Cell
B.simpleCell
toHeaderRow :: [Blocks] -> [Row]
toHeaderRow [Blocks]
l = [[Blocks] -> Row
toRow [Blocks]
l | Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Blocks]
l)]
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Caption
-> [(Alignment, ColWidth)]
-> TableHead
-> [TableBody]
-> TableFoot
-> Blocks
B.table Caption
B.emptyCaption
[(Alignment, ColWidth)]
attrs
((Text, [Text], [(Text, Text)]) -> [Row] -> TableHead
TableHead (Text, [Text], [(Text, Text)])
nullAttr forall a b. (a -> b) -> a -> b
$ [Blocks] -> [Row]
toHeaderRow (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd [(Alignment, Blocks)]
headerRow))
[(Text, [Text], [(Text, Text)])
-> RowHeadColumns -> [Row] -> [Row] -> TableBody
TableBody (Text, [Text], [(Text, Text)])
nullAttr RowHeadColumns
0 [] forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map ([Blocks] -> Row
toRow forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd)) [[(Alignment, Blocks)]]
body]
((Text, [Text], [(Text, Text)]) -> [Row] -> TableFoot
TableFoot (Text, [Text], [(Text, Text)])
nullAttr [])
tableRows :: PandocMonad m => DWParser m [[(Alignment, B.Blocks)]]
tableRows :: forall (m :: * -> *).
PandocMonad m =>
DWParser m [[(Alignment, Blocks)]]
tableRows = forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall (m :: * -> *).
PandocMonad m =>
DWParser m [(Alignment, Blocks)]
tableRow
tableRow :: PandocMonad m => DWParser m [(Alignment, B.Blocks)]
tableRow :: forall (m :: * -> *).
PandocMonad m =>
DWParser m [(Alignment, Blocks)]
tableRow = 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 forall (m :: * -> *).
PandocMonad m =>
DWParser m (Alignment, Blocks)
tableCell forall (m :: * -> *). PandocMonad m => DWParser m Char
tableRowEnd
tableRowEnd :: PandocMonad m => DWParser m Char
tableRowEnd :: forall (m :: * -> *). PandocMonad m => DWParser m Char
tableRowEnd = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => DWParser m Char
tableCellSeparator forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
eol
tableCellSeparator :: PandocMonad m => DWParser m Char
tableCellSeparator :: forall (m :: * -> *). PandocMonad m => DWParser m Char
tableCellSeparator = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|' forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'^'
tableCell :: PandocMonad m => DWParser m (Alignment, B.Blocks)
tableCell :: forall (m :: * -> *).
PandocMonad m =>
DWParser m (Alignment, Blocks)
tableCell = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ (forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second (Inlines -> Blocks
B.plain forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
B.trimInlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (Alignment, [Inlines])
cellContent
where
cellContent :: ParsecT Sources ParserState m (Alignment, [Inlines])
cellContent = do
forall (m :: * -> *). PandocMonad m => DWParser m Char
tableCellSeparator
[Inlines]
cellInline <- forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inlineUnconsolidatedWhitespace (forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall (m :: * -> *). PandocMonad m => DWParser m Char
tableCellSeparator)
let left :: Bool
left = [Inlines
B.space, Inlines
B.space] forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` [Inlines]
cellInline
let right :: Bool
right = [Inlines
B.space, Inlines
B.space] forall a. Eq a => [a] -> [a] -> Bool
`isSuffixOf` [Inlines]
cellInline
let alignment :: Alignment
alignment = case (Bool
left, Bool
right) of
(Bool
True, Bool
True) -> Alignment
AlignCenter
(Bool
True, Bool
False) -> Alignment
AlignRight
(Bool
False, Bool
True) -> Alignment
AlignLeft
(Bool
False, Bool
False) -> Alignment
AlignDefault
forall (m :: * -> *) a. Monad m => a -> m a
return (Alignment
alignment, [Inlines]
cellInline)
blockCode :: PandocMonad m => DWParser m B.Blocks
blockCode :: forall (m :: * -> *). PandocMonad m => DWParser m Blocks
blockCode = forall (m :: * -> *) a.
PandocMonad m =>
((Text, [Text], [(Text, Text)]) -> Text -> a)
-> Text -> DWParser m a
codeTag (Text, [Text], [(Text, Text)]) -> Text -> Blocks
B.codeBlockWith Text
"code"
blockFile :: PandocMonad m => DWParser m B.Blocks
blockFile :: forall (m :: * -> *). PandocMonad m => DWParser m Blocks
blockFile = forall (m :: * -> *) a.
PandocMonad m =>
((Text, [Text], [(Text, Text)]) -> Text -> a)
-> Text -> DWParser m a
codeTag (Text, [Text], [(Text, Text)]) -> Text -> Blocks
B.codeBlockWith Text
"file"
para :: PandocMonad m => DWParser m B.Blocks
para :: forall (m :: * -> *). PandocMonad m => DWParser m Blocks
para = Inlines -> Blocks
result forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall 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 forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline ParsecT Sources ParserState m ()
endOfParaElement
where
endOfParaElement :: ParsecT Sources ParserState m ()
endOfParaElement = forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall a b. (a -> b) -> a -> b
$ forall {u}. ParsecT Sources u m ()
endOfInput forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT Sources u m ()
endOfPara forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m ()
newBlockElement
endOfInput :: ParsecT Sources u m ()
endOfInput = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
endOfPara :: ParsecT Sources u m ()
endOfPara = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
newBlockElement :: ParsecT Sources ParserState m ()
newBlockElement = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Functor f => f a -> f ()
void forall (m :: * -> *). PandocMonad m => DWParser m Blocks
blockElements
result :: Inlines -> Blocks
result Inlines
content = if forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
F.all (forall a. Eq a => a -> a -> Bool
==Inline
Space) Inlines
content
then forall a. Monoid a => a
mempty
else Inlines -> Blocks
B.para forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.trimInlines Inlines
content