{-# LANGUAGE FlexibleContexts  #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}
{-# LANGUAGE ViewPatterns      #-}
{- |
   Module      : Text.Pandoc.Readers.DokuWiki
   Copyright   : Copyright (C) 2018-2020 Alexander Krotov
   License     : GNU GPL, version 2 or above

   Maintainer  : Alexander Krotov <ilabdsf@gmail.com>
   Stability   : alpha
   Portability : portable

Conversion of DokuWiki text to 'Pandoc' document.
-}
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.List (transpose)
import Data.Maybe (fromMaybe, catMaybes)
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.Error (PandocError (PandocParsecError))
import Text.Pandoc.Options
import Text.Pandoc.Parsing hiding (enclosed, nested)
import Text.Pandoc.Shared (crFilter, trim, stringify, tshow)

-- | Read DokuWiki from an input string and return a Pandoc document.
readDokuWiki :: PandocMonad m
             => ReaderOptions
             -> Text
             -> m Pandoc
readDokuWiki :: ReaderOptions -> Text -> m Pandoc
readDokuWiki ReaderOptions
opts Text
s = do
  let input :: Text
input = Text -> Text
crFilter Text
s
  Either ParseError Pandoc
res <- ParsecT Text ParserState m Pandoc
-> ParserState
-> SourceName
-> Text
-> m (Either ParseError Pandoc)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a)
runParserT ParsecT Text ParserState m Pandoc
forall (m :: * -> *). PandocMonad m => DWParser m Pandoc
parseDokuWiki ParserState
forall a. Default a => a
def {stateOptions :: ReaderOptions
stateOptions = ReaderOptions
opts } SourceName
"source" Text
input
  case Either ParseError Pandoc
res of
       Left ParseError
e  -> PandocError -> m Pandoc
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (PandocError -> m Pandoc) -> PandocError -> m Pandoc
forall a b. (a -> b) -> a -> b
$ Text -> ParseError -> PandocError
PandocParsecError Text
input ParseError
e
       Right Pandoc
d -> Pandoc -> m Pandoc
forall (m :: * -> *) a. Monad m => a -> m a
return Pandoc
d

type DWParser = ParserT Text ParserState

-- * Utility functions

-- | Parse end-of-line, which can be either a newline or end-of-file.
eol :: Stream s m Char => ParserT s st m ()
eol :: ParserT s st m ()
eol = ParsecT s st m Char -> ParserT s st m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT s st m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline ParserT s st m () -> ParserT s st m () -> ParserT s st m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT s st m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof

nested :: PandocMonad m => DWParser m a -> DWParser m a
nested :: DWParser m a -> DWParser m a
nested DWParser m a
p = do
  Int
nestlevel <- ParserState -> Int
stateMaxNestingLevel (ParserState -> Int)
-> ParsecT Text ParserState m ParserState
-> ParsecT Text ParserState m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>  ParsecT Text ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Bool -> ParsecT Text ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text ParserState m ())
-> Bool -> ParsecT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ Int
nestlevel Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
  (ParserState -> ParserState) -> ParsecT Text ParserState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((ParserState -> ParserState) -> ParsecT Text ParserState m ())
-> (ParserState -> ParserState) -> ParsecT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ \ParserState
st -> ParserState
st{ stateMaxNestingLevel :: Int
stateMaxNestingLevel = ParserState -> Int
stateMaxNestingLevel ParserState
st Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 }
  a
res <- DWParser m a
p
  (ParserState -> ParserState) -> ParsecT Text ParserState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((ParserState -> ParserState) -> ParsecT Text ParserState m ())
-> (ParserState -> ParserState) -> ParsecT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ \ParserState
st -> ParserState
st{ stateMaxNestingLevel :: Int
stateMaxNestingLevel = Int
nestlevel }
  a -> DWParser m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
res

guardColumnOne :: PandocMonad m => DWParser m ()
guardColumnOne :: DWParser m ()
guardColumnOne = ParsecT Text ParserState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition ParsecT Text ParserState m SourcePos
-> (SourcePos -> DWParser m ()) -> DWParser m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \SourcePos
pos -> Bool -> DWParser m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (SourcePos -> Int
sourceColumn SourcePos
pos Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1)

-- | Parse DokuWiki document.
parseDokuWiki :: PandocMonad m => DWParser m Pandoc
parseDokuWiki :: DWParser m Pandoc
parseDokuWiki =
  Blocks -> Pandoc
B.doc (Blocks -> Pandoc) -> ([Blocks] -> Blocks) -> [Blocks] -> Pandoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat ([Blocks] -> Pandoc)
-> ParsecT Text ParserState m [Blocks] -> DWParser m Pandoc
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m Blocks
-> ParsecT Text ParserState m [Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text ParserState m Blocks
forall (m :: * -> *). PandocMonad m => DWParser m Blocks
block DWParser m Pandoc
-> ParsecT Text ParserState m () -> DWParser m Pandoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text ParserState m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces DWParser m Pandoc
-> ParsecT Text ParserState m () -> DWParser m Pandoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text ParserState m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof

-- | Parse <code> and <file> attributes
codeLanguage :: PandocMonad m => DWParser m (Text, [Text], [(Text, Text)])
codeLanguage :: DWParser m (Text, [Text], [(Text, Text)])
codeLanguage = DWParser m (Text, [Text], [(Text, Text)])
-> DWParser m (Text, [Text], [(Text, Text)])
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m (Text, [Text], [(Text, Text)])
 -> DWParser m (Text, [Text], [(Text, Text)]))
-> DWParser m (Text, [Text], [(Text, Text)])
-> DWParser m (Text, [Text], [(Text, Text)])
forall a b. (a -> b) -> a -> b
$ do
  Text
rawLang <- Text
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"-" (ParserT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParserT Text ParserState m Char
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParserT Text ParserState m Char
-> ParserT Text ParserState m Char
-> ParsecT Text ParserState m Text
forall s (m :: * -> *) t st a.
Stream s m t =>
ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
manyTillChar ParserT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (ParserT Text ParserState m Char -> ParserT Text ParserState m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParserT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParserT Text ParserState m Char
-> ParserT Text ParserState m Char
-> ParserT Text ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParserT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'>')))
  let attr :: [Text]
attr = case Text
rawLang of
               Text
"-" -> []
               Text
l -> [Text
l]
  (Text, [Text], [(Text, Text)])
-> DWParser m (Text, [Text], [(Text, Text)])
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
"", [Text]
attr, [])

-- | Generic parser for <code> and <file> tags
codeTag :: PandocMonad m
        => ((Text, [Text], [(Text, Text)]) -> Text -> a)
        -> Text
        -> DWParser m a
codeTag :: ((Text, [Text], [(Text, Text)]) -> Text -> a)
-> Text -> DWParser m a
codeTag (Text, [Text], [(Text, Text)]) -> Text -> a
f Text
tag = DWParser m a -> DWParser m a
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m a -> DWParser m a) -> DWParser m a -> DWParser m a
forall a b. (a -> b) -> a -> b
$ (Text, [Text], [(Text, Text)]) -> Text -> a
f
  ((Text, [Text], [(Text, Text)]) -> Text -> a)
-> ParsecT Text ParserState m Char
-> ParsecT
     Text ParserState m ((Text, [Text], [(Text, Text)]) -> Text -> a)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'<'
  ParsecT
  Text ParserState m ((Text, [Text], [(Text, Text)]) -> Text -> a)
-> ParsecT Text ParserState m Text
-> ParsecT
     Text ParserState m ((Text, [Text], [(Text, Text)]) -> Text -> a)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  Text -> ParsecT Text ParserState m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
tag
  ParsecT
  Text ParserState m ((Text, [Text], [(Text, Text)]) -> Text -> a)
-> ParsecT Text ParserState m (Text, [Text], [(Text, Text)])
-> ParsecT Text ParserState m (Text -> a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text ParserState m (Text, [Text], [(Text, Text)])
forall (m :: * -> *).
PandocMonad m =>
DWParser m (Text, [Text], [(Text, Text)])
codeLanguage
  ParsecT Text ParserState m (Text -> a)
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m (Text -> a)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'>')
  ParsecT Text ParserState m (Text -> a)
-> ParsecT Text ParserState m ()
-> ParsecT Text ParserState m (Text -> a)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (ParsecT Text ParserState m Char
-> ParsecT Text ParserState m ()
-> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text ParserState m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
eol)
  ParsecT Text ParserState m (Text -> a)
-> ParsecT Text ParserState m Text -> DWParser m a
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m Text
forall s (m :: * -> *) t st a.
Stream s m t =>
ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
manyTillChar ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m SourceName
 -> ParsecT Text ParserState m SourceName)
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m SourceName
forall a b. (a -> b) -> a -> b
$ SourceName -> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"</" ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m SourceName
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Text -> ParsecT Text ParserState m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
tag ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m SourceName
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'>')

-- * Inline parsers

-- | Parse any inline element but softbreak.
inline' :: PandocMonad m => DWParser m B.Inlines
inline' :: DWParser m Inlines
inline' = DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
whitespace
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
br
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
bold
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
italic
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
underlined
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
nowiki
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
percent
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
link
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
image
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
monospaced
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
subscript
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
superscript
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
deleted
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
footnote
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inlineCode
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inlineFile
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inlineHtml
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inlinePhp
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
autoLink
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
autoEmail
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
notoc
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
nocache
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
str
      DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
symbol
      DWParser m Inlines -> SourceName -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> SourceName -> ParsecT s u m a
<?> SourceName
"inline"

-- | Parse any inline element, including soft break.
inline :: PandocMonad m => DWParser m B.Inlines
inline :: DWParser m Inlines
inline = DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
endline DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline'

endline :: PandocMonad m => DWParser m B.Inlines
endline :: DWParser m Inlines
endline = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines
B.softbreak Inlines -> ParsecT Text ParserState m () -> DWParser m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
linebreak

whitespace :: PandocMonad m => DWParser m B.Inlines
whitespace :: DWParser m Inlines
whitespace = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines
B.space Inlines -> ParsecT Text ParserState m () -> DWParser m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar

br :: PandocMonad m => DWParser m B.Inlines
br :: DWParser m Inlines
br = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines
B.linebreak Inlines
-> ParsecT Text ParserState m SourceName -> DWParser m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ SourceName -> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"\\\\" DWParser m Inlines
-> ParsecT Text ParserState m Char -> DWParser m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
space

linebreak :: PandocMonad m => DWParser m B.Inlines
linebreak :: DWParser m Inlines
linebreak = ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline ParsecT Text ParserState m Char
-> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text ParserState m Char -> ParsecT Text 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 Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline ParsecT Text ParserState m ()
-> DWParser m Inlines -> DWParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (DWParser m Inlines
forall u. ParsecT Text u m Inlines
lastNewline DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
innerNewline)
  where lastNewline :: ParsecT Text u m Inlines
lastNewline  = Inlines
forall a. Monoid a => a
mempty Inlines -> ParsecT Text u m () -> ParsecT Text u m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
        innerNewline :: DWParser m Inlines
innerNewline = Inlines -> DWParser m Inlines
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 :: 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 =
  [c] -> c
forall a. Monoid a => [a] -> a
mconcat ([c] -> c) -> ParsecT Text ParserState m [c] -> DWParser m c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m [c] -> ParsecT Text ParserState m [c]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m a
start DWParser m a
-> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text ParserState m Inlines -> ParsecT Text 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 Text ParserState m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
whitespace ParsecT Text ParserState m ()
-> ParsecT Text ParserState m [c] -> ParsecT Text ParserState m [c]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> DWParser m c -> DWParser m b -> ParsecT Text ParserState m [c]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT 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 :: DWParser m a -> (DWParser m a -> DWParser m b) -> DWParser m b
enclosed DWParser m a
sep DWParser m a -> DWParser m b
p = DWParser m a
-> DWParser m a -> (DWParser m a -> DWParser m b) -> DWParser m 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 DWParser m a
sep (DWParser m a -> DWParser m a
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 :: DWParser m a -> DWParser m Inlines
nestedInlines DWParser m a
end = DWParser m Inlines
innerSpace DWParser m Inlines -> DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Inlines
nestedInline
  where
    innerSpace :: DWParser m Inlines
innerSpace   = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
whitespace DWParser m Inlines
-> ParsecT Text ParserState m () -> DWParser m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* DWParser m a -> ParsecT Text ParserState m ()
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 :: DWParser m Inlines
nestedInline = DWParser m Inlines -> ParsecT Text ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
whitespace ParsecT Text ParserState m ()
-> DWParser m Inlines -> DWParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> DWParser m Inlines -> DWParser m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
DWParser m a -> DWParser m a
nested DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline

bold :: PandocMonad m => DWParser m B.Inlines
bold :: DWParser m Inlines
bold = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.strong (Inlines -> Inlines) -> DWParser m Inlines -> DWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DWParser m SourceName
-> (DWParser m SourceName -> DWParser m Inlines)
-> DWParser m Inlines
forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
DWParser m a -> (DWParser m a -> DWParser m b) -> DWParser m b
enclosed (SourceName -> DWParser m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"**") DWParser m SourceName -> DWParser m Inlines
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Inlines
nestedInlines

italic :: PandocMonad m => DWParser m B.Inlines
italic :: DWParser m Inlines
italic = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.emph (Inlines -> Inlines) -> DWParser m Inlines -> DWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DWParser m SourceName
-> (DWParser m SourceName -> DWParser m Inlines)
-> DWParser m Inlines
forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
DWParser m a -> (DWParser m a -> DWParser m b) -> DWParser m b
enclosed (SourceName -> DWParser m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"//") DWParser m SourceName -> DWParser m Inlines
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Inlines
nestedInlines

underlined :: PandocMonad m => DWParser m B.Inlines
underlined :: DWParser m Inlines
underlined = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.underline (Inlines -> Inlines) -> DWParser m Inlines -> DWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DWParser m SourceName
-> (DWParser m SourceName -> DWParser m Inlines)
-> DWParser m Inlines
forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
DWParser m a -> (DWParser m a -> DWParser m b) -> DWParser m b
enclosed (SourceName -> DWParser m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"__") DWParser m SourceName -> DWParser m Inlines
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Inlines
nestedInlines

nowiki :: PandocMonad m => DWParser m B.Inlines
nowiki :: DWParser m Inlines
nowiki = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.text (Text -> Inlines)
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m (Text -> Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ SourceName -> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"<nowiki>" ParsecT Text ParserState m (Text -> Inlines)
-> ParsecT Text ParserState m Text -> DWParser m Inlines
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParserT Text ParserState m Char
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m Text
forall s (m :: * -> *) t st a.
Stream s m t =>
ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
manyTillChar ParserT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m SourceName
 -> ParsecT Text ParserState m SourceName)
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m SourceName
forall a b. (a -> b) -> a -> b
$ SourceName -> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"</nowiki>")

percent :: PandocMonad m => DWParser m B.Inlines
percent :: DWParser m Inlines
percent = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.text (Text -> Inlines)
-> ParsecT Text ParserState m Text -> DWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DWParser m SourceName
-> (DWParser m SourceName -> ParsecT Text ParserState m Text)
-> ParsecT Text ParserState m Text
forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
DWParser m a -> (DWParser m a -> DWParser m b) -> DWParser m b
enclosed (SourceName -> DWParser m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"%%") DWParser m SourceName -> ParsecT Text ParserState m Text
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 :: DWParser m a -> DWParser m Text
nestedText DWParser m a
end = DWParser m Text
innerSpace DWParser m Text -> DWParser m Text -> DWParser m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Int -> ParsecT Text ParserState m Char -> DWParser m Text
forall s (m :: * -> *) st.
(Stream s m Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
nonspaceChar
  where
    innerSpace :: DWParser m Text
innerSpace = DWParser m Text -> DWParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Text -> DWParser m Text)
-> DWParser m Text -> DWParser m Text
forall a b. (a -> b) -> a -> b
$ ParsecT Text ParserState m Char -> DWParser m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar DWParser m Text -> ParsecT Text ParserState m () -> DWParser m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* DWParser m a -> ParsecT Text ParserState m ()
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 :: DWParser m Inlines
monospaced = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.code (Text -> Inlines) -> (Inlines -> Text) -> Inlines -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Text] -> Text
T.concat ([Text] -> Text) -> (Inlines -> [Text]) -> Inlines -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Inline -> Text) -> [Inline] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Inline -> Text
forall a. Walkable Inline a => a -> Text
stringify ([Inline] -> [Text]) -> (Inlines -> [Inline]) -> Inlines -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inline]
forall a. Many a -> [a]
B.toList) (Inlines -> Inlines) -> DWParser m Inlines -> DWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DWParser m SourceName
-> (DWParser m SourceName -> DWParser m Inlines)
-> DWParser m Inlines
forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
DWParser m a -> (DWParser m a -> DWParser m b) -> DWParser m b
enclosed (SourceName -> DWParser m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"''") DWParser m SourceName -> DWParser m Inlines
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Inlines
nestedInlines

subscript :: PandocMonad m => DWParser m B.Inlines
subscript :: DWParser m Inlines
subscript = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.subscript (Inlines -> Inlines) -> DWParser m Inlines -> DWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DWParser m SourceName
-> DWParser m SourceName
-> (DWParser m SourceName -> DWParser m Inlines)
-> DWParser m Inlines
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 (SourceName -> DWParser m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"<sub>") (DWParser m SourceName -> DWParser m SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m SourceName -> DWParser m SourceName)
-> DWParser m SourceName -> DWParser m SourceName
forall a b. (a -> b) -> a -> b
$ SourceName -> DWParser m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"</sub>") DWParser m SourceName -> DWParser m Inlines
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Inlines
nestedInlines

superscript :: PandocMonad m => DWParser m B.Inlines
superscript :: DWParser m Inlines
superscript = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.superscript (Inlines -> Inlines) -> DWParser m Inlines -> DWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DWParser m SourceName
-> DWParser m SourceName
-> (DWParser m SourceName -> DWParser m Inlines)
-> DWParser m Inlines
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 (SourceName -> DWParser m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"<sup>") (DWParser m SourceName -> DWParser m SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m SourceName -> DWParser m SourceName)
-> DWParser m SourceName -> DWParser m SourceName
forall a b. (a -> b) -> a -> b
$ SourceName -> DWParser m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"</sup>") DWParser m SourceName -> DWParser m Inlines
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Inlines
nestedInlines

deleted :: PandocMonad m => DWParser m B.Inlines
deleted :: DWParser m Inlines
deleted = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.strikeout (Inlines -> Inlines) -> DWParser m Inlines -> DWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DWParser m SourceName
-> DWParser m SourceName
-> (DWParser m SourceName -> DWParser m Inlines)
-> DWParser m Inlines
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 (SourceName -> DWParser m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"<del>") (DWParser m SourceName -> DWParser m SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m SourceName -> DWParser m SourceName)
-> DWParser m SourceName -> DWParser m SourceName
forall a b. (a -> b) -> a -> b
$ SourceName -> DWParser m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"</del>") DWParser m SourceName -> DWParser m Inlines
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Inlines
nestedInlines

-- | Parse a footnote.
footnote :: PandocMonad m => DWParser m B.Inlines
footnote :: DWParser m Inlines
footnote = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Blocks -> Inlines
B.note (Blocks -> Inlines) -> (Inlines -> Blocks) -> Inlines -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Blocks
B.para (Inlines -> Inlines) -> DWParser m Inlines -> DWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DWParser m SourceName
-> DWParser m SourceName
-> (DWParser m SourceName -> DWParser m Inlines)
-> DWParser m Inlines
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 (SourceName -> DWParser m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"((") (DWParser m SourceName -> DWParser m SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m SourceName -> DWParser m SourceName)
-> DWParser m SourceName -> DWParser m SourceName
forall a b. (a -> b) -> a -> b
$ SourceName -> DWParser m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"))") DWParser m SourceName -> DWParser m Inlines
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
DWParser m a -> DWParser m Inlines
nestedInlines

inlineCode :: PandocMonad m => DWParser m B.Inlines
inlineCode :: DWParser m Inlines
inlineCode = ((Text, [Text], [(Text, Text)]) -> Text -> Inlines)
-> Text -> DWParser m Inlines
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 :: DWParser m Inlines
inlineFile = ((Text, [Text], [(Text, Text)]) -> Text -> Inlines)
-> Text -> DWParser m Inlines
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"

inlineHtml :: PandocMonad m => DWParser m B.Inlines
inlineHtml :: DWParser m Inlines
inlineHtml = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines
B.rawInline Text
"html" (Text -> Inlines)
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m (Text -> Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ SourceName -> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"<html>" ParsecT Text ParserState m (Text -> Inlines)
-> ParsecT Text ParserState m Text -> DWParser m Inlines
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParserT Text ParserState m Char
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m Text
forall s (m :: * -> *) t st a.
Stream s m t =>
ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
manyTillChar ParserT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m SourceName
 -> ParsecT Text ParserState m SourceName)
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m SourceName
forall a b. (a -> b) -> a -> b
$ SourceName -> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"</html>")

inlinePhp :: PandocMonad m => DWParser m B.Inlines
inlinePhp :: DWParser m Inlines
inlinePhp = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ (Text, [Text], [(Text, Text)]) -> Text -> Inlines
B.codeWith (Text
"", [Text
"php"], []) (Text -> Inlines)
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m (Text -> Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ SourceName -> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"<php>" ParsecT Text ParserState m (Text -> Inlines)
-> ParsecT Text ParserState m Text -> DWParser m Inlines
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParserT Text ParserState m Char
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m Text
forall s (m :: * -> *) t st a.
Stream s m t =>
ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
manyTillChar ParserT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m SourceName
 -> ParsecT Text ParserState m SourceName)
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m SourceName
forall a b. (a -> b) -> a -> b
$ SourceName -> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"</php>")

makeLink :: (Text, Text) -> B.Inlines
makeLink :: (Text, Text) -> Inlines
makeLink (Text
text, Text
url) = Text -> Text -> Inlines -> Inlines
B.link Text
url Text
"" (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
text

autoEmail :: PandocMonad m => DWParser m B.Inlines
autoEmail :: DWParser m Inlines
autoEmail = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ do
  ParserState
state <- ParsecT Text ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Bool -> ParsecT Text ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text ParserState m ())
-> Bool -> ParsecT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserState -> Bool
stateAllowLinks ParserState
state
  (Text, Text) -> Inlines
makeLink ((Text, Text) -> Inlines)
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m ((Text, Text) -> Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'<' ParsecT Text ParserState m ((Text, Text) -> Inlines)
-> ParsecT Text ParserState m (Text, Text) -> DWParser m Inlines
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text ParserState m (Text, Text)
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m (Text, Text)
emailAddress DWParser m Inlines
-> ParsecT Text ParserState m Char -> DWParser m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'>'

autoLink :: PandocMonad m => DWParser m B.Inlines
autoLink :: DWParser m Inlines
autoLink = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ do
  ParserState
state <- ParsecT Text ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Bool -> ParsecT Text ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text ParserState m ())
-> Bool -> ParsecT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserState -> Bool
stateAllowLinks ParserState
state
  (Text
text, Text
url) <- ParserT Text ParserState m (Text, Text)
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m (Text, Text)
uri
  Bool -> ParsecT Text ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text ParserState m ())
-> Bool -> ParsecT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ Char -> Bool
checkLink (Text -> Char
T.last Text
url)
  Inlines -> DWParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> DWParser m Inlines) -> Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ (Text, Text) -> Inlines
makeLink (Text
text, Text
url)
  where
    checkLink :: Char -> Bool
checkLink Char
c
      | Char
c Char -> Char -> Bool
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 :: DWParser m Inlines
notoc = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines
forall a. Monoid a => a
mempty Inlines
-> ParsecT Text ParserState m SourceName -> DWParser m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ SourceName -> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"~~NOTOC~~"

nocache :: PandocMonad m => DWParser m B.Inlines
nocache :: DWParser m Inlines
nocache = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines
forall a. Monoid a => a
mempty Inlines
-> ParsecT Text ParserState m SourceName -> DWParser m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ SourceName -> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"~~NOCACHE~~"

str :: PandocMonad m => DWParser m B.Inlines
str :: DWParser m Inlines
str = Text -> Inlines
B.str (Text -> Inlines)
-> ParsecT Text ParserState m Text -> DWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParserT Text ParserState m Char -> ParsecT Text ParserState m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char ParserT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
alphaNum ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Int
-> ParserT Text ParserState m Char
-> ParsecT Text ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 ParserT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
characterReference)

symbol :: PandocMonad m => DWParser m B.Inlines
symbol :: DWParser m Inlines
symbol = Text -> Inlines
B.str (Text -> Inlines)
-> ParsecT Text ParserState m Text -> DWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
nonspaceChar

link :: PandocMonad m => DWParser m B.Inlines
link :: DWParser m Inlines
link = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ do
  ParserState
st <- ParsecT Text ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Bool -> ParsecT Text ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text ParserState m ())
-> Bool -> ParsecT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserState -> Bool
stateAllowLinks ParserState
st
  ParserState -> ParsecT Text ParserState m ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState (ParserState -> ParsecT Text ParserState m ())
-> ParserState -> ParsecT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserState
st{ stateAllowLinks :: Bool
stateAllowLinks = Bool
False }
  Inlines
l <- DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
linkText
  ParserState -> ParsecT Text ParserState m ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState (ParserState -> ParsecT Text ParserState m ())
-> ParserState -> ParsecT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserState
st{ stateAllowLinks :: Bool
stateAllowLinks = Bool
True }
  Inlines -> DWParser m Inlines
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 Char -> SourceName -> Bool
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 (Char -> Char -> Bool
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 Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":" Text -> Text -> 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 (Char -> Char -> Bool
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
"/" ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile (Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
".") ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ Text -> Text -> [Text]
T.splitOn Text
":" (Text -> [Text]) -> Text -> [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
"/" Text -> Text -> 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 (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
':') Text
url

-- Parse link or image
parseLink :: PandocMonad m
          => (Text -> Maybe B.Inlines -> B.Inlines)
          -> Text
          -> Text
          -> DWParser m B.Inlines
parseLink :: (Text -> Maybe Inlines -> Inlines)
-> Text -> Text -> DWParser m Inlines
parseLink Text -> Maybe Inlines -> Inlines
f Text
l Text
r = Text -> Maybe Inlines -> Inlines
f
  (Text -> Maybe Inlines -> Inlines)
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m (Text -> Maybe Inlines -> Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  Text -> ParsecT Text ParserState m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
l
  ParsecT Text ParserState m (Text -> Maybe Inlines -> Inlines)
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m (Maybe Inlines -> Inlines)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParserT Text ParserState m Char
-> ParserT Text ParserState m () -> ParsecT Text ParserState m Text
forall end s (m :: * -> *) t st.
(Show end, Stream s m t) =>
ParserT s st m Char -> ParserT s st m end -> ParserT s st m Text
many1TillChar ParserT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParserT Text ParserState m Char -> ParserT Text ParserState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Char -> ParserT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|') ParserT Text ParserState m ()
-> ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m Text -> ParserT Text ParserState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT Text ParserState m Text -> ParserT Text ParserState m ())
-> ParsecT Text ParserState m Text -> ParserT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Text ParserState m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
r)))
  ParsecT Text ParserState m (Maybe Inlines -> Inlines)
-> ParsecT Text ParserState m (Maybe Inlines) -> DWParser m Inlines
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> DWParser m Inlines -> ParsecT Text ParserState m (Maybe Inlines)
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 (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT Text ParserState m [Inlines] -> DWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> ParserT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|' ParserT Text ParserState m Char
-> ParsecT Text ParserState m [Inlines]
-> ParsecT Text ParserState m [Inlines]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> DWParser m Inlines
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m [Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill DWParser m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline (ParsecT Text ParserState m Text -> ParsecT Text ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m Text
 -> ParsecT Text ParserState m Text)
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
forall a b. (a -> b) -> a -> b
$ ParsecT Text ParserState m Text -> ParsecT Text ParserState m Text
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Text ParserState m Text
 -> ParsecT Text ParserState m Text)
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Text ParserState m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
r)))
  DWParser m Inlines
-> ParsecT Text ParserState m Text -> DWParser m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  Text -> ParsecT Text ParserState m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
r

-- | Split Interwiki link into left and right part
-- | Return Nothing if it is not Interwiki link
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 Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'.') Text
path of
    (Text
l, Text -> Maybe (Char, Text)
T.uncons -> Just (Char
'>', Text
r)) -> (Text, Text) -> Maybe (Text, Text)
forall a. a -> Maybe a
Just (Text
l, Text
r)
    (Text, Text)
_ -> Maybe (Text, Text)
forall a. Maybe a
Nothing

interwikiToUrl :: Text -> Text -> Text
interwikiToUrl :: Text -> Text -> Text
interwikiToUrl Text
"callto" Text
page = Text
"callto://" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"doku" Text
page = Text
"https://www.dokuwiki.org/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"phpfn" Text
page = Text
"https://secure.php.net/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"tel" Text
page = Text
"tel:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"wp" Text
page = Text
"https://en.wikipedia.org/wiki/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"wpde" Text
page = Text
"https://de.wikipedia.org/wiki/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"wpes" Text
page = Text
"https://es.wikipedia.org/wiki/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"wpfr" Text
page = Text
"https://fr.wikipedia.org/wiki/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"wpjp" Text
page = Text
"https://jp.wikipedia.org/wiki/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
"wppl" Text
page = Text
"https://pl.wikipedia.org/wiki/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
page
interwikiToUrl Text
unknown Text
page = Text
unknown Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
">" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
page

linkText :: PandocMonad m => DWParser m B.Inlines
linkText :: DWParser m Inlines
linkText = (Text -> Maybe Inlines -> Inlines)
-> Text -> Text -> DWParser m Inlines
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
"" (Inlines -> Maybe Inlines -> Inlines
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

-- Matches strings like "100x100" (width x height) and "50" (width)
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 (Text -> Maybe (Char, Text)) -> Text -> Maybe (Char, Text)
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 = Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
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 (Text -> Maybe (Char, Text)) -> Text -> Maybe (Char, Text)
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Text
T.dropWhile Char -> Bool
isDigit Text
s of
        Just (Char
'x', Text
xs) -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
xs
        Maybe (Char, Text)
_ -> Maybe Text
forall a. Maybe a
Nothing

image :: PandocMonad m => DWParser m B.Inlines
image :: DWParser m Inlines
image = DWParser m Inlines -> DWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Inlines -> DWParser m Inlines)
-> DWParser m Inlines -> DWParser m Inlines
forall a b. (a -> b) -> a -> b
$ (Text -> Maybe Inlines -> Inlines)
-> Text -> Text -> DWParser m Inlines
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
"" (Inlines -> Maybe Inlines -> Inlines
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
"" (Inlines -> Maybe Inlines -> Inlines
forall a. a -> Maybe a -> a
fromMaybe Inlines
defaultDescription Maybe Inlines
description)
      where
        (Text
path', Text
parameters) = (Char -> Bool) -> Text -> (Text, Text)
T.span (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'?') (Text -> (Text, Text)) -> Text -> (Text, Text)
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
"&" (Text -> [Text]) -> Text -> [Text]
forall a b. (a -> b) -> a -> b
$ Int -> Text -> Text
T.drop Int
1 Text
parameters
        linkOnly :: Bool
linkOnly = Text
"linkonly" Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text]
parameterList
        (Maybe Text
width, Maybe Text
height) = (Maybe Text, Maybe Text)
-> (Text -> (Maybe Text, Maybe Text))
-> Maybe Text
-> (Maybe Text, Maybe Text)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe Text
forall a. Maybe a
Nothing, Maybe Text
forall a. Maybe a
Nothing) Text -> (Maybe Text, Maybe Text)
parseWidthHeight ((Text -> Bool) -> [Text] -> Maybe Text
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
F.find Text -> Bool
isWidthHeightParameter [Text]
parameterList)
        attributes :: [(Text, Text)]
attributes = [Maybe (Text, Text)] -> [(Text, Text)]
forall a. [Maybe a] -> [a]
catMaybes [(Text -> (Text, Text)) -> Maybe Text -> Maybe (Text, Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text
"width",) Maybe Text
width, (Text -> (Text, Text)) -> Maybe Text -> Maybe (Text, Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text
"height",) Maybe Text
height]
        defaultDescription :: Inlines
defaultDescription = Text -> Inlines
B.str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Text
urlToText Text
path'

-- * Block parsers

block :: PandocMonad m => DWParser m B.Blocks
block :: DWParser m Blocks
block = do
  Blocks
res <- Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT Text ParserState m () -> DWParser m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline
         DWParser m Blocks -> DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Blocks
forall (m :: * -> *). PandocMonad m => DWParser m Blocks
blockElements
         DWParser m Blocks -> DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Blocks
forall (m :: * -> *). PandocMonad m => DWParser m Blocks
para
  ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline
  Text -> ParsecT Text ParserState m ()
forall (m :: * -> *). PandocMonad m => Text -> m ()
trace (Int -> Text -> Text
T.take Int
60 (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ [Block] -> Text
forall a. Show a => a -> Text
tshow ([Block] -> Text) -> [Block] -> Text
forall a b. (a -> b) -> a -> b
$ Blocks -> [Block]
forall a. Many a -> [a]
B.toList Blocks
res)
  Blocks -> DWParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
res

blockElements :: PandocMonad m => DWParser m B.Blocks
blockElements :: DWParser m Blocks
blockElements = DWParser m Blocks
forall (m :: * -> *). PandocMonad m => DWParser m Blocks
horizontalLine
            DWParser m Blocks -> DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Blocks
forall (m :: * -> *). PandocMonad m => DWParser m Blocks
header
            DWParser m Blocks -> DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> DWParser m Blocks
forall (m :: * -> *). PandocMonad m => Text -> DWParser m Blocks
list Text
"  "
            DWParser m Blocks -> DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Blocks
forall (m :: * -> *). PandocMonad m => DWParser m Blocks
indentedCode
            DWParser m Blocks -> DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Blocks
forall (m :: * -> *). PandocMonad m => DWParser m Blocks
quote
            DWParser m Blocks -> DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Blocks
forall (m :: * -> *). PandocMonad m => DWParser m Blocks
blockCode
            DWParser m Blocks -> DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Blocks
forall (m :: * -> *). PandocMonad m => DWParser m Blocks
blockFile
            DWParser m Blocks -> DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Blocks
forall (m :: * -> *). PandocMonad m => DWParser m Blocks
blockHtml
            DWParser m Blocks -> DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Blocks
forall (m :: * -> *). PandocMonad m => DWParser m Blocks
blockPhp
            DWParser m Blocks -> DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Blocks
forall (m :: * -> *). PandocMonad m => DWParser m Blocks
table

horizontalLine :: PandocMonad m => DWParser m B.Blocks
horizontalLine :: DWParser m Blocks
horizontalLine = DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Blocks -> DWParser m Blocks)
-> DWParser m Blocks -> DWParser m Blocks
forall a b. (a -> b) -> a -> b
$ Blocks
B.horizontalRule Blocks
-> ParsecT Text ParserState m SourceName -> DWParser m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ SourceName -> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"---" DWParser m Blocks
-> ParsecT Text ParserState m SourceName -> DWParser m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text ParserState m Char
-> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'-') DWParser m Blocks
-> ParsecT Text ParserState m () -> DWParser m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text ParserState m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
eol

header :: PandocMonad m => DWParser m B.Blocks
header :: DWParser m Blocks
header = DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Blocks -> DWParser m Blocks)
-> DWParser m Blocks -> DWParser m Blocks
forall a b. (a -> b) -> a -> b
$ do
  DWParser m ()
forall (m :: * -> *). PandocMonad m => DWParser m ()
guardColumnOne
  SourceName
eqs <- ParsecT Text ParserState m Char
-> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'=')
  let lev :: Int
lev = SourceName -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length SourceName
eqs
  Bool -> DWParser m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> DWParser m ()) -> Bool -> DWParser m ()
forall a b. (a -> b) -> a -> b
$ Int
lev Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
7
  Inlines
contents <- Inlines -> Inlines
B.trimInlines (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT Text ParserState m [Inlines]
-> ParsecT Text ParserState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m Inlines
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m [Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Text ParserState m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline (ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m SourceName
 -> ParsecT Text ParserState m SourceName)
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m SourceName
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'=' ParsecT Text ParserState m Char
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m SourceName
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'='))
  (Text, [Text], [(Text, Text)])
attr <- (Text, [Text], [(Text, Text)])
-> Inlines
-> ParserT Text ParserState m (Text, [Text], [(Text, Text)])
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st, HasLogMessages st,
 HasIdentifierList st) =>
(Text, [Text], [(Text, Text)])
-> Inlines -> ParserT s st m (Text, [Text], [(Text, Text)])
registerHeader (Text, [Text], [(Text, Text)])
nullAttr Inlines
contents
  Blocks -> DWParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> DWParser m Blocks) -> Blocks -> DWParser m Blocks
forall a b. (a -> b) -> a -> b
$ (Text, [Text], [(Text, Text)]) -> Int -> Inlines -> Blocks
B.headerWith (Text, [Text], [(Text, Text)])
attr (Int
7 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
lev) Inlines
contents

list :: PandocMonad m => Text -> DWParser m B.Blocks
list :: Text -> DWParser m Blocks
list Text
prefix = Text -> DWParser m Blocks
forall (m :: * -> *). PandocMonad m => Text -> DWParser m Blocks
bulletList Text
prefix DWParser m Blocks -> DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> DWParser m Blocks
forall (m :: * -> *). PandocMonad m => Text -> DWParser m Blocks
orderedList Text
prefix

bulletList :: PandocMonad m => Text -> DWParser m B.Blocks
bulletList :: Text -> DWParser m Blocks
bulletList Text
prefix = DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Blocks -> DWParser m Blocks)
-> DWParser m Blocks -> DWParser m Blocks
forall a b. (a -> b) -> a -> b
$ [Blocks] -> Blocks
B.bulletList ([Blocks] -> Blocks)
-> ParsecT Text ParserState m [Blocks] -> DWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Char -> ParsecT Text ParserState m [Blocks]
forall (m :: * -> *).
PandocMonad m =>
Text -> Char -> DWParser m [Blocks]
parseList Text
prefix Char
'*'

orderedList :: PandocMonad m => Text -> DWParser m B.Blocks
orderedList :: Text -> DWParser m Blocks
orderedList Text
prefix = DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Blocks -> DWParser m Blocks)
-> DWParser m Blocks -> DWParser m Blocks
forall a b. (a -> b) -> a -> b
$ [Blocks] -> Blocks
B.orderedList ([Blocks] -> Blocks)
-> ParsecT Text ParserState m [Blocks] -> DWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Char -> ParsecT Text ParserState m [Blocks]
forall (m :: * -> *).
PandocMonad m =>
Text -> Char -> DWParser m [Blocks]
parseList Text
prefix Char
'-'

parseList :: PandocMonad m
          => Text
          -> Char
          -> DWParser m [B.Blocks]
parseList :: Text -> Char -> DWParser m [Blocks]
parseList Text
prefix Char
marker =
  ParsecT Text ParserState m Blocks -> DWParser m [Blocks]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
(<>) (Blocks -> Blocks -> Blocks)
-> ParsecT Text ParserState m Blocks
-> ParsecT Text ParserState m (Blocks -> Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m Blocks
item ParsecT Text ParserState m (Blocks -> Blocks)
-> ParsecT Text ParserState m Blocks
-> ParsecT Text ParserState m Blocks
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ([Blocks] -> Blocks)
-> DWParser m [Blocks] -> ParsecT Text ParserState m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat (ParsecT Text ParserState m Blocks -> DWParser m [Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text ParserState m Blocks
continuation))
  where
    continuation :: ParsecT Text ParserState m Blocks
continuation = ParsecT Text ParserState m Blocks
-> ParsecT Text ParserState m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m Blocks
 -> ParsecT Text ParserState m Blocks)
-> ParsecT Text ParserState m Blocks
-> ParsecT Text ParserState m Blocks
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Text ParserState m Blocks
forall (m :: * -> *). PandocMonad m => Text -> DWParser m Blocks
list (Text
"  " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
prefix)
    item :: ParsecT Text ParserState m Blocks
item = ParsecT Text ParserState m Blocks
-> ParsecT Text ParserState m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m Blocks
 -> ParsecT Text ParserState m Blocks)
-> ParsecT Text ParserState m Blocks
-> ParsecT Text ParserState m Blocks
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Text ParserState m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
prefix ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
marker ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
' ' ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Blocks
-> ParsecT Text ParserState m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text ParserState m Blocks
itemContents
    itemContents :: ParsecT Text ParserState m Blocks
itemContents = Inlines -> Blocks
B.plain (Inlines -> Blocks)
-> ([Inlines] -> Inlines) -> [Inlines] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Blocks)
-> ParsecT Text ParserState m [Inlines]
-> ParsecT Text ParserState m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Text ParserState m Inlines
-> ParserT Text ParserState m ()
-> ParsecT Text ParserState m [Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till ParserT Text ParserState m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline' ParserT Text ParserState m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
eol

indentedCode :: PandocMonad m => DWParser m B.Blocks
indentedCode :: DWParser m Blocks
indentedCode = DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Blocks -> DWParser m Blocks)
-> DWParser m Blocks -> DWParser m Blocks
forall a b. (a -> b) -> a -> b
$ Text -> Blocks
B.codeBlock (Text -> Blocks) -> ([Text] -> Text) -> [Text] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Text
T.unlines ([Text] -> Blocks)
-> ParsecT Text ParserState m [Text] -> DWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m [Text]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Text ParserState m Text
forall u. ParsecT Text u m Text
indentedLine
 where
   indentedLine :: ParsecT Text u m Text
indentedLine = ParsecT Text u m Text -> ParsecT Text u m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m Text -> ParsecT Text u m Text)
-> ParsecT Text u m Text -> ParsecT Text u m Text
forall a b. (a -> b) -> a -> b
$ SourceName -> ParsecT Text u m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"  " ParsecT Text u m SourceName
-> ParsecT Text u m Text -> ParsecT Text u m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParserT Text u m Char
-> ParserT Text u m () -> ParsecT Text u m Text
forall s (m :: * -> *) t st a.
Stream s m t =>
ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
manyTillChar ParserT Text u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar ParserT Text u m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
eol

quote :: PandocMonad m => DWParser m B.Blocks
quote :: DWParser m Blocks
quote = DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Blocks -> DWParser m Blocks)
-> DWParser m Blocks -> DWParser m Blocks
forall a b. (a -> b) -> a -> b
$ Int -> DWParser m Blocks
nestedQuote Int
0
  where
    prefix :: Int -> ParsecT s u m SourceName
prefix Int
level = Int -> ParsecT s u m Char -> ParsecT s u m SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
level (Char -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'>')
    contents :: Int -> DWParser m Blocks
contents Int
level = Int -> DWParser m Blocks
nestedQuote Int
level DWParser m Blocks -> DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DWParser m Blocks
quoteLine
    quoteLine :: DWParser m Blocks
quoteLine = DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Blocks -> DWParser m Blocks)
-> DWParser m Blocks -> DWParser m Blocks
forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
B.plain (Inlines -> Blocks)
-> ([Inlines] -> Inlines) -> [Inlines] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
B.trimInlines (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Blocks)
-> ParsecT Text ParserState m [Inlines] -> DWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Text ParserState m Inlines
-> ParserT Text ParserState m ()
-> ParsecT Text ParserState m [Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till ParserT Text ParserState m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline' ParserT Text ParserState m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
eol
    quoteContents :: Int -> DWParser m Blocks
quoteContents Int
level = Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
(<>) (Blocks -> Blocks -> Blocks)
-> DWParser m Blocks
-> ParsecT Text ParserState m (Blocks -> Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> DWParser m Blocks
contents Int
level ParsecT Text ParserState m (Blocks -> Blocks)
-> DWParser m Blocks -> DWParser m Blocks
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> DWParser m Blocks
quoteContinuation Int
level
    quoteContinuation :: Int -> DWParser m Blocks
quoteContinuation Int
level = [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat ([Blocks] -> Blocks)
-> ParsecT Text ParserState m [Blocks] -> DWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DWParser m Blocks -> ParsecT Text ParserState m [Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Blocks -> DWParser m Blocks)
-> DWParser m Blocks -> DWParser m Blocks
forall a b. (a -> b) -> a -> b
$ Int -> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
Int -> ParsecT s u m SourceName
prefix Int
level ParsecT Text ParserState m SourceName
-> DWParser m Blocks -> DWParser m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> DWParser m Blocks
contents Int
level)
    nestedQuote :: Int -> DWParser m Blocks
nestedQuote Int
level = Blocks -> Blocks
B.blockQuote (Blocks -> Blocks)
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m (Blocks -> Blocks)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'>' ParsecT Text ParserState m (Blocks -> Blocks)
-> DWParser m Blocks -> DWParser m Blocks
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> DWParser m Blocks
quoteContents (Int
level Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 :: Int)

blockHtml :: PandocMonad m => DWParser m B.Blocks
blockHtml :: DWParser m Blocks
blockHtml = DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Blocks -> DWParser m Blocks)
-> DWParser m Blocks -> DWParser m Blocks
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Blocks
B.rawBlock Text
"html"
  (Text -> Blocks)
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m (Text -> Blocks)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  SourceName -> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"<HTML>"
  ParsecT Text ParserState m (Text -> Blocks)
-> ParsecT Text ParserState m ()
-> ParsecT Text ParserState m (Text -> Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (ParsecT Text ParserState m Char
-> ParsecT Text ParserState m ()
-> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text ParserState m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
eol)
  ParsecT Text ParserState m (Text -> Blocks)
-> ParsecT Text ParserState m Text -> DWParser m Blocks
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m Text
forall s (m :: * -> *) t st a.
Stream s m t =>
ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
manyTillChar ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m SourceName
 -> ParsecT Text ParserState m SourceName)
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m SourceName
forall a b. (a -> b) -> a -> b
$ SourceName -> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"</HTML>")

blockPhp :: PandocMonad m => DWParser m B.Blocks
blockPhp :: DWParser m Blocks
blockPhp = DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Blocks -> DWParser m Blocks)
-> DWParser m Blocks -> DWParser m Blocks
forall a b. (a -> b) -> a -> b
$ (Text, [Text], [(Text, Text)]) -> Text -> Blocks
B.codeBlockWith (Text
"", [Text
"php"], [])
  (Text -> Blocks)
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m (Text -> Blocks)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  SourceName -> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"<PHP>"
  ParsecT Text ParserState m (Text -> Blocks)
-> ParsecT Text ParserState m ()
-> ParsecT Text ParserState m (Text -> Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (ParsecT Text ParserState m Char
-> ParsecT Text ParserState m ()
-> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text ParserState m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
eol)
  ParsecT Text ParserState m (Text -> Blocks)
-> ParsecT Text ParserState m Text -> DWParser m Blocks
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m Text
forall s (m :: * -> *) t st a.
Stream s m t =>
ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
manyTillChar ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m SourceName
 -> ParsecT Text ParserState m SourceName)
-> ParsecT Text ParserState m SourceName
-> ParsecT Text ParserState m SourceName
forall a b. (a -> b) -> a -> b
$ SourceName -> ParsecT Text ParserState m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"</PHP>")

table :: PandocMonad m => DWParser m B.Blocks
table :: DWParser m Blocks
table = do
  Char
firstSeparator <- ParsecT Text ParserState m Char -> ParsecT Text 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 Text ParserState m Char
forall (m :: * -> *). PandocMonad m => DWParser m Char
tableCellSeparator
  [[Blocks]]
rows <- DWParser m [[Blocks]]
forall (m :: * -> *). PandocMonad m => DWParser m [[Blocks]]
tableRows
  let ([Blocks]
headerRow, [[Blocks]]
body) = if Char
firstSeparator Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'^'
                            then ([[Blocks]] -> [Blocks]
forall a. [a] -> a
head [[Blocks]]
rows, [[Blocks]] -> [[Blocks]]
forall a. [a] -> [a]
tail [[Blocks]]
rows)
                            else ([], [[Blocks]]
rows)
  let attrs :: [(Alignment, ColWidth)]
attrs = (Alignment
AlignDefault, ColWidth
ColWidthDefault) (Alignment, ColWidth) -> [[Blocks]] -> [(Alignment, ColWidth)]
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [[Blocks]] -> [[Blocks]]
forall a. [[a]] -> [[a]]
transpose [[Blocks]]
rows
  let toRow :: [Blocks] -> Row
toRow = (Text, [Text], [(Text, Text)]) -> [Cell] -> Row
Row (Text, [Text], [(Text, Text)])
nullAttr ([Cell] -> Row) -> ([Blocks] -> [Cell]) -> [Blocks] -> Row
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Blocks -> Cell) -> [Blocks] -> [Cell]
forall a b. (a -> b) -> [a] -> [b]
map Blocks -> Cell
B.simpleCell
      toHeaderRow :: [Blocks] -> [Row]
toHeaderRow [Blocks]
l = [[Blocks] -> Row
toRow [Blocks]
l | Bool -> Bool
not ([Blocks] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Blocks]
l)]
  Blocks -> DWParser m Blocks
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Blocks -> DWParser m Blocks) -> Blocks -> DWParser m Blocks
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 ([Row] -> TableHead) -> [Row] -> TableHead
forall a b. (a -> b) -> a -> b
$ [Blocks] -> [Row]
toHeaderRow [Blocks]
headerRow)
                 [(Text, [Text], [(Text, Text)])
-> RowHeadColumns -> [Row] -> [Row] -> TableBody
TableBody (Text, [Text], [(Text, Text)])
nullAttr RowHeadColumns
0 [] ([Row] -> TableBody) -> [Row] -> TableBody
forall a b. (a -> b) -> a -> b
$ ([Blocks] -> Row) -> [[Blocks]] -> [Row]
forall a b. (a -> b) -> [a] -> [b]
map [Blocks] -> Row
toRow [[Blocks]]
body]
                 ((Text, [Text], [(Text, Text)]) -> [Row] -> TableFoot
TableFoot (Text, [Text], [(Text, Text)])
nullAttr [])

tableRows :: PandocMonad m => DWParser m [[B.Blocks]]
tableRows :: DWParser m [[Blocks]]
tableRows = ParsecT Text ParserState m [Blocks] -> DWParser m [[Blocks]]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Text ParserState m [Blocks]
forall (m :: * -> *). PandocMonad m => DWParser m [Blocks]
tableRow

tableRow :: PandocMonad m => DWParser m [B.Blocks]
tableRow :: DWParser m [Blocks]
tableRow = ParserT Text ParserState m Blocks
-> ParserT Text ParserState m Char -> DWParser m [Blocks]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till ParserT Text ParserState m Blocks
forall (m :: * -> *). PandocMonad m => DWParser m Blocks
tableCell ParserT Text ParserState m Char
forall (m :: * -> *). PandocMonad m => DWParser m Char
tableRowEnd

tableRowEnd :: PandocMonad m => DWParser m Char
tableRowEnd :: DWParser m Char
tableRowEnd = DWParser m Char -> DWParser m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Char -> DWParser m Char)
-> DWParser m Char -> DWParser m Char
forall a b. (a -> b) -> a -> b
$ DWParser m Char
forall (m :: * -> *). PandocMonad m => DWParser m Char
tableCellSeparator DWParser m Char
-> ParsecT Text ParserState m SourceName -> DWParser m Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* DWParser m Char
-> ParsecT Text ParserState m ()
-> ParsecT Text ParserState m SourceName
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 DWParser m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text ParserState m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
eol

tableCellSeparator :: PandocMonad m => DWParser m Char
tableCellSeparator :: DWParser m Char
tableCellSeparator = Char -> DWParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|' DWParser m Char -> DWParser m Char -> DWParser m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> DWParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'^'

tableCell :: PandocMonad m => DWParser m B.Blocks
tableCell :: DWParser m Blocks
tableCell = DWParser m Blocks -> DWParser m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (DWParser m Blocks -> DWParser m Blocks)
-> DWParser m Blocks -> DWParser m Blocks
forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
B.plain (Inlines -> Blocks)
-> ([Inlines] -> Inlines) -> [Inlines] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
B.trimInlines (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Blocks)
-> ParsecT Text ParserState m [Inlines] -> DWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Text ParserState m [Inlines]
normalCell ParsecT Text ParserState m [Inlines]
-> ParsecT Text ParserState m [Inlines]
-> ParsecT Text ParserState m [Inlines]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text ParserState m [Inlines]
headerCell)
  where
    normalCell :: ParsecT Text ParserState m [Inlines]
normalCell = Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|' ParsecT Text ParserState m Char
-> ParsecT Text ParserState m [Inlines]
-> ParsecT Text ParserState m [Inlines]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text ParserState m Inlines
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m [Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Text ParserState m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline' (ParsecT Text ParserState m Char -> ParsecT Text 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 Text ParserState m Char
forall (m :: * -> *). PandocMonad m => DWParser m Char
tableCellSeparator)
    headerCell :: ParsecT Text ParserState m [Inlines]
headerCell = Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'^' ParsecT Text ParserState m Char
-> ParsecT Text ParserState m [Inlines]
-> ParsecT Text ParserState m [Inlines]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text ParserState m Inlines
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m [Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Text ParserState m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline' (ParsecT Text ParserState m Char -> ParsecT Text 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 Text ParserState m Char
forall (m :: * -> *). PandocMonad m => DWParser m Char
tableCellSeparator)

blockCode :: PandocMonad m => DWParser m B.Blocks
blockCode :: DWParser m Blocks
blockCode = ((Text, [Text], [(Text, Text)]) -> Text -> Blocks)
-> Text -> DWParser m Blocks
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 :: DWParser m Blocks
blockFile = ((Text, [Text], [(Text, Text)]) -> Text -> Blocks)
-> Text -> DWParser m Blocks
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 :: DWParser m Blocks
para = Inlines -> Blocks
result (Inlines -> Blocks)
-> ([Inlines] -> Inlines) -> [Inlines] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Blocks)
-> ParsecT Text ParserState m [Inlines] -> DWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Text ParserState m Inlines
-> ParserT Text ParserState m ()
-> ParsecT Text ParserState m [Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till ParserT Text ParserState m Inlines
forall (m :: * -> *). PandocMonad m => DWParser m Inlines
inline ParserT Text ParserState m ()
endOfParaElement
 where
   endOfParaElement :: ParserT Text ParserState m ()
endOfParaElement = ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParserT Text ParserState m () -> ParserT Text ParserState m ())
-> ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserT Text ParserState m ()
forall u. ParsecT Text u m ()
endOfInput ParserT Text ParserState m ()
-> ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT Text ParserState m ()
forall u. ParsecT Text u m ()
endOfPara ParserT Text ParserState m ()
-> ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT Text ParserState m ()
newBlockElement
   endOfInput :: ParsecT Text u m ()
endOfInput       = ParsecT Text u m () -> ParsecT Text u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m () -> ParsecT Text u m ())
-> ParsecT Text u m () -> ParsecT Text u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Text u m Char -> ParsecT Text u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Text u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline ParsecT Text u m () -> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
skipSpaces ParsecT Text u m () -> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
   endOfPara :: ParsecT Text u m ()
endOfPara        = ParsecT Text u m () -> ParsecT Text u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m () -> ParsecT Text u m ())
-> ParsecT Text u m () -> ParsecT Text u m ()
forall a b. (a -> b) -> a -> b
$ ParserT Text u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline ParserT Text u m Char -> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParserT Text u m Char -> ParsecT Text u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParserT Text u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline
   newBlockElement :: ParserT Text ParserState m ()
newBlockElement  = ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParserT Text ParserState m () -> ParserT Text ParserState m ())
-> ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline ParserT Text ParserState m Char
-> ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> DWParser m Blocks -> ParserT Text ParserState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void DWParser m Blocks
forall (m :: * -> *). PandocMonad m => DWParser m Blocks
blockElements
   result :: Inlines -> Blocks
result Inlines
content   = if (Inline -> Bool) -> Inlines -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
F.all (Inline -> Inline -> Bool
forall a. Eq a => a -> a -> Bool
==Inline
Space) Inlines
content
                      then Blocks
forall a. Monoid a => a
mempty
                      else Inlines -> Blocks
B.para (Inlines -> Blocks) -> Inlines -> Blocks
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.trimInlines Inlines
content