{-# LANGUAGE OverloadedStrings #-}
{- |
   Module      : Text.Pandoc.Readers.MediaWiki
   Copyright   : Copyright (C) 2012-2023 John MacFarlane
   License     : GNU GPL, version 2 or above

   Maintainer  : John MacFarlane <jgm@berkeley.edu>
   Stability   : alpha
   Portability : portable

Conversion of mediawiki text to 'Pandoc' document.
-}
{-
TODO:
_ correctly handle tables within tables
_ parse templates?
-}
module Text.Pandoc.Readers.MediaWiki ( readMediaWiki ) where

import Control.Monad
import Control.Monad.Except (throwError)
import Data.Char (isDigit, isLetter, isSpace)
import qualified Data.Foldable as F
import Data.List (intersperse)
import Data.Maybe (fromMaybe, maybeToList)
import Data.Sequence (ViewL (..), viewl, (<|))
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as T
import Text.HTML.TagSoup
import Text.Pandoc.Builder (Blocks, Inlines, trimInlines)
import qualified Text.Pandoc.Builder as B
import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
import Text.Pandoc.Definition
import Text.Pandoc.Logging
import Text.Pandoc.Options
import Text.Pandoc.Parsing hiding (tableCaption)
import Text.Pandoc.Readers.HTML (htmlTag, isBlockTag, isCommentTag, toAttr)
import Text.Pandoc.Shared (safeRead, stringify, stripTrailingNewlines,
                           trim, splitTextBy, tshow, formatCode)
import Text.Pandoc.XML (fromEntities)

-- | Read mediawiki from an input string and return a Pandoc document.
readMediaWiki :: (PandocMonad m, ToSources a)
              => ReaderOptions
              -> a
              -> m Pandoc
readMediaWiki :: forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> a -> m Pandoc
readMediaWiki ReaderOptions
opts a
s = do
  let sources :: Sources
sources = forall a. ToSources a => a -> Sources
toSources a
s
  Either PandocError Pandoc
parsed <- forall (m :: * -> *) t st a.
(Monad m, ToSources t) =>
ParsecT Sources st m a -> st -> t -> m (Either PandocError a)
readWithM forall (m :: * -> *). PandocMonad m => MWParser m Pandoc
parseMediaWiki MWState{ mwOptions :: ReaderOptions
mwOptions = ReaderOptions
opts
                                            , mwMaxNestingLevel :: Int
mwMaxNestingLevel = Int
4
                                            , mwNextLinkNumber :: Int
mwNextLinkNumber  = Int
1
                                            , mwCategoryLinks :: [Inlines]
mwCategoryLinks = []
                                            , mwIdentifierList :: Set Text
mwIdentifierList = forall a. Set a
Set.empty
                                            , mwLogMessages :: [LogMessage]
mwLogMessages = []
                                            , mwInTT :: Bool
mwInTT = Bool
False
                                            }
            Sources
sources
  case Either PandocError Pandoc
parsed of
    Right Pandoc
result -> forall (m :: * -> *) a. Monad m => a -> m a
return Pandoc
result
    Left PandocError
e       -> forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError PandocError
e

data MWState = MWState { MWState -> ReaderOptions
mwOptions         :: ReaderOptions
                       , MWState -> Int
mwMaxNestingLevel :: Int
                       , MWState -> Int
mwNextLinkNumber  :: Int
                       , MWState -> [Inlines]
mwCategoryLinks   :: [Inlines]
                       , MWState -> Set Text
mwIdentifierList  :: Set.Set Text
                       , MWState -> [LogMessage]
mwLogMessages     :: [LogMessage]
                       , MWState -> Bool
mwInTT            :: Bool
                       }

type MWParser m = ParsecT Sources MWState m

instance HasReaderOptions MWState where
  extractReaderOptions :: MWState -> ReaderOptions
extractReaderOptions = MWState -> ReaderOptions
mwOptions

instance HasIdentifierList MWState where
  extractIdentifierList :: MWState -> Set Text
extractIdentifierList     = MWState -> Set Text
mwIdentifierList
  updateIdentifierList :: (Set Text -> Set Text) -> MWState -> MWState
updateIdentifierList Set Text -> Set Text
f MWState
st = MWState
st{ mwIdentifierList :: Set Text
mwIdentifierList = Set Text -> Set Text
f forall a b. (a -> b) -> a -> b
$ MWState -> Set Text
mwIdentifierList MWState
st }

instance HasLogMessages MWState where
  addLogMessage :: LogMessage -> MWState -> MWState
addLogMessage LogMessage
m MWState
s = MWState
s{ mwLogMessages :: [LogMessage]
mwLogMessages = LogMessage
m forall a. a -> [a] -> [a]
: MWState -> [LogMessage]
mwLogMessages MWState
s }
  getLogMessages :: MWState -> [LogMessage]
getLogMessages = forall a. [a] -> [a]
reverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. MWState -> [LogMessage]
mwLogMessages

--
-- auxiliary functions
--

specialChars :: [Char]
specialChars :: [Char]
specialChars = [Char]
"'[]<=&*{}|\":\\"

spaceChars :: [Char]
spaceChars :: [Char]
spaceChars = [Char]
" \n\t"

sym :: PandocMonad m => Text -> MWParser m ()
sym :: forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
sym Text
s = () forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string forall a b. (a -> b) -> a -> b
$ Text -> [Char]
T.unpack Text
s)

newBlockTags :: [Text]
newBlockTags :: [Text]
newBlockTags = [Text
"haskell",Text
"syntaxhighlight",Text
"source",Text
"gallery",Text
"references"]

isBlockTag' :: Tag Text -> Bool
isBlockTag' :: Tag Text -> Bool
isBlockTag' tag :: Tag Text
tag@(TagOpen Text
t [Attribute Text]
_) = (Tag Text -> Bool
isBlockTag Tag Text
tag Bool -> Bool -> Bool
|| Text
t forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text]
newBlockTags) Bool -> Bool -> Bool
&&
  Text
t forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Text]
eitherBlockOrInline
isBlockTag' (TagClose Text
"ref") = Bool
True -- needed so 'special' doesn't parse it
isBlockTag' tag :: Tag Text
tag@(TagClose Text
t) = (Tag Text -> Bool
isBlockTag Tag Text
tag Bool -> Bool -> Bool
|| Text
t forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text]
newBlockTags) Bool -> Bool -> Bool
&&
  Text
t forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Text]
eitherBlockOrInline
isBlockTag' Tag Text
tag = Tag Text -> Bool
isBlockTag Tag Text
tag

isInlineTag' :: Tag Text -> Bool
isInlineTag' :: Tag Text -> Bool
isInlineTag' (TagComment Text
_) = Bool
True
isInlineTag' (TagClose Text
"ref") = Bool
False -- see below inlineTag
isInlineTag' Tag Text
t              = Bool -> Bool
not (Tag Text -> Bool
isBlockTag' Tag Text
t)

eitherBlockOrInline :: [Text]
eitherBlockOrInline :: [Text]
eitherBlockOrInline = [Text
"applet", Text
"button", Text
"del", Text
"iframe", Text
"ins",
                               Text
"map", Text
"area", Text
"object"]

htmlComment :: PandocMonad m => MWParser m ()
htmlComment :: forall (m :: * -> *). PandocMonad m => MWParser m ()
htmlComment = () forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag Tag Text -> Bool
isCommentTag

inlinesInTags :: PandocMonad m => Text -> MWParser m Inlines
inlinesInTags :: forall (m :: * -> *). PandocMonad m => Text -> MWParser m Inlines
inlinesInTags Text
tag = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  (Tag Text
_,Text
raw) <- forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> [Attribute str] -> Tag str
TagOpen Text
tag [])
  if (Char -> Bool) -> Text -> Bool
T.any (forall a. Eq a => a -> a -> Bool
== Char
'/') Text
raw   -- self-closing tag
     then forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
     else Inlines -> Inlines
trimInlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
            forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => MWParser m Inlines
inline (forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> Tag str
TagClose Text
tag))

blocksInTags :: PandocMonad m => Text -> MWParser m Blocks
blocksInTags :: forall (m :: * -> *). PandocMonad m => Text -> MWParser m Blocks
blocksInTags Text
tag = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  (Tag Text
_,Text
raw) <- forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> [Attribute str] -> Tag str
TagOpen Text
tag [])
  let closer :: ParsecT Sources MWState m (Tag Text, Text)
closer = if Text
tag forall a. Eq a => a -> a -> Bool
== Text
"li"
                  then forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> Tag str
TagClose (Text
"li" :: Text))
                     forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (
                              forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> [Attribute str] -> Tag str
TagOpen (Text
"li" :: Text) [])
                          forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> Tag str
TagClose (Text
"ol" :: Text))
                          forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> Tag str
TagClose (Text
"ul" :: Text)))
                  else forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> Tag str
TagClose Text
tag)
  if (Char -> Bool) -> Text -> Bool
T.any (forall a. Eq a => a -> a -> Bool
== Char
'/') Text
raw   -- self-closing tag
     then forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
     else forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => MWParser m Blocks
block ParsecT Sources MWState m (Tag Text, Text)
closer

textInTags :: PandocMonad m => Text -> MWParser m Text
textInTags :: forall (m :: * -> *). PandocMonad m => Text -> MWParser m Text
textInTags Text
tag = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  (Tag Text
_,Text
raw) <- forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> [Attribute str] -> Tag str
TagOpen Text
tag [])
  if (Char -> Bool) -> Text -> Bool
T.any (forall a. Eq a => a -> a -> Bool
== Char
'/') Text
raw   -- self-closing tag
     then forall (m :: * -> *) a. Monad m => a -> m a
return Text
""
     else [Char] -> Text
T.pack forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> Tag str
TagClose Text
tag))

--
-- main parser
--

parseMediaWiki :: PandocMonad m => MWParser m Pandoc
parseMediaWiki :: forall (m :: * -> *). PandocMonad m => MWParser m Pandoc
parseMediaWiki = do
  Blocks
bs <- forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall (m :: * -> *). PandocMonad m => MWParser m Blocks
block
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces
  forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
  [Inlines]
categoryLinks <- forall a. [a] -> [a]
reverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. MWState -> [Inlines]
mwCategoryLinks forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  let categories :: Blocks
categories = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Inlines]
categoryLinks
                      then forall a. Monoid a => a
mempty
                      else Inlines -> Blocks
B.para forall a b. (a -> b) -> a -> b
$ forall a. Monoid a => [a] -> a
mconcat forall a b. (a -> b) -> a -> b
$ forall a. a -> [a] -> [a]
intersperse Inlines
B.space [Inlines]
categoryLinks
  forall (m :: * -> *) st s.
(PandocMonad m, HasLogMessages st) =>
ParsecT s st m ()
reportLogMessages
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Blocks -> Pandoc
B.doc forall a b. (a -> b) -> a -> b
$ Blocks
bs forall a. Semigroup a => a -> a -> a
<> Blocks
categories

--
-- block parsers
--

block :: PandocMonad m => MWParser m Blocks
block :: forall (m :: * -> *). PandocMonad m => MWParser m Blocks
block = do
  Blocks
res <- forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
     forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Blocks
table
     forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Blocks
header
     forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Blocks
hrule
     forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Blocks
orderedList
     forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Blocks
bulletList
     forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Blocks
definitionList
     forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => MWParser m ()
htmlComment)
     forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Blocks
preformatted
     forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Blocks
blockTag
     forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Text -> Text -> Blocks
B.rawBlock Text
"mediawiki" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => MWParser m Text
template)
     forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Blocks
para
  forall (m :: * -> *). PandocMonad m => Text -> m ()
trace (Int -> Text -> Text
T.take Int
60 forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> Text
tshow forall a b. (a -> b) -> a -> b
$ forall a. Many a -> [a]
B.toList Blocks
res)
  forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
res

para :: PandocMonad m => MWParser m Blocks
para :: forall (m :: * -> *). PandocMonad m => MWParser m Blocks
para = do
  Inlines
contents <- Inlines -> Inlines
trimInlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall (m :: * -> *). PandocMonad m => MWParser m Inlines
inline
  if forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
F.all (forall a. Eq a => a -> a -> Bool
==Inline
Space) Inlines
contents
     then forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
     else case forall a. Many a -> [a]
B.toList Inlines
contents of
         -- For the MediaWiki format all images are considered figures
         [Image Attr
attr [Inline]
figureCaption (Text
src, Text
title)] ->
             forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> Inlines -> Text -> Text -> Blocks
B.simpleFigureWith
                 Attr
attr (forall a. [a] -> Many a
B.fromList [Inline]
figureCaption) Text
src Text
title
         [Inline]
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
B.para Inlines
contents

table :: PandocMonad m => MWParser m Blocks
table :: forall (m :: * -> *). PandocMonad m => MWParser m Blocks
table = do
  forall (m :: * -> *). PandocMonad m => MWParser m ()
tableStart
  [Attribute Text]
styles <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] forall a b. (a -> b) -> a -> b
$
               forall (m :: * -> *). PandocMonad m => MWParser m [Attribute Text]
parseAttrs forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|')
  forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
  forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => MWParser m Text
template forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
  forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
blanklines
  let tableWidth :: Double
tableWidth = case forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"width" [Attribute Text]
styles of
                         Just Text
w  -> forall a. a -> Maybe a -> a
fromMaybe Double
1.0 forall a b. (a -> b) -> a -> b
$ Text -> Maybe Double
parseWidth Text
w
                         Maybe Text
Nothing -> Double
1.0
  Inlines
caption <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option forall a. Monoid a => a
mempty forall (m :: * -> *). PandocMonad m => MWParser m Inlines
tableCaption
  forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional forall (m :: * -> *). PandocMonad m => MWParser m ()
rowsep
  Bool
hasheader <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False forall a b. (a -> b) -> a -> b
$ Bool
True forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'!')
  ([Double]
cellspecs',[Cell]
hdr) <- forall a b. [(a, b)] -> ([a], [b])
unzip forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => MWParser m [(Double, Cell)]
tableRow
  let widths :: [Double]
widths = forall a b. (a -> b) -> [a] -> [b]
map (Double
tableWidth forall a. Num a => a -> a -> a
*) [Double]
cellspecs'
  let restwidth :: Double
restwidth = Double
tableWidth forall a. Num a => a -> a -> a
- forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum [Double]
widths
  let zerocols :: Int
zerocols = forall (t :: * -> *) a. Foldable t => t a -> Int
length forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
filter (forall a. Eq a => a -> a -> Bool
==Double
0.0) [Double]
widths
  let defaultwidth :: ColWidth
defaultwidth = if Int
zerocols forall a. Eq a => a -> a -> Bool
== Int
0 Bool -> Bool -> Bool
|| Int
zerocols forall a. Eq a => a -> a -> Bool
== forall (t :: * -> *) a. Foldable t => t a -> Int
length [Double]
widths
                        then ColWidth
ColWidthDefault
                        else Double -> ColWidth
ColWidth forall a b. (a -> b) -> a -> b
$ Double
restwidth forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
zerocols
  let widths' :: [ColWidth]
widths' = forall a b. (a -> b) -> [a] -> [b]
map (\Double
w -> if Double
w forall a. Ord a => a -> a -> Bool
> Double
0 then Double -> ColWidth
ColWidth Double
w else ColWidth
defaultwidth) [Double]
widths
  let cellspecs :: [(Alignment, ColWidth)]
cellspecs = forall a b. [a] -> [b] -> [(a, b)]
zip ([Cell] -> [Alignment]
calculateAlignments [Cell]
hdr) [ColWidth]
widths'
  [[Cell]]
rows' <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => MWParser m ()
rowsep forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => MWParser m [(Double, Cell)]
tableRow)
  forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
blanklines
  forall (m :: * -> *). PandocMonad m => MWParser m ()
tableEnd
  let ([Cell]
headers,[[Cell]]
rows) = if Bool
hasheader
                          then ([Cell]
hdr, [[Cell]]
rows')
                          else ([], [Cell]
hdrforall a. a -> [a] -> [a]
:[[Cell]]
rows')
  let toRow :: [Cell] -> Row
toRow = Attr -> [Cell] -> Row
Row Attr
nullAttr
      toHeaderRow :: [Cell] -> [Row]
toHeaderRow [Cell]
l = [[Cell] -> Row
toRow [Cell]
l | Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Cell]
l)]
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Caption
-> [(Alignment, ColWidth)]
-> TableHead
-> [TableBody]
-> TableFoot
-> Blocks
B.table (Blocks -> Caption
B.simpleCaption forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
B.plain Inlines
caption)
                   [(Alignment, ColWidth)]
cellspecs
                   (Attr -> [Row] -> TableHead
TableHead Attr
nullAttr forall a b. (a -> b) -> a -> b
$ [Cell] -> [Row]
toHeaderRow [Cell]
headers)
                   [Attr -> RowHeadColumns -> [Row] -> [Row] -> TableBody
TableBody Attr
nullAttr RowHeadColumns
0 [] forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map [Cell] -> Row
toRow [[Cell]]
rows]
                   (Attr -> [Row] -> TableFoot
TableFoot Attr
nullAttr [])

calculateAlignments :: [Cell] -> [Alignment]
calculateAlignments :: [Cell] -> [Alignment]
calculateAlignments = forall a b. (a -> b) -> [a] -> [b]
map Cell -> Alignment
cellAligns
  where
    cellAligns :: Cell -> Alignment
    cellAligns :: Cell -> Alignment
cellAligns (Cell Attr
_ Alignment
align RowSpan
_ ColSpan
_ [Block]
_) = Alignment
align

parseAttrs :: PandocMonad m => MWParser m [(Text,Text)]
parseAttrs :: forall (m :: * -> *). PandocMonad m => MWParser m [Attribute Text]
parseAttrs = forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall (m :: * -> *). PandocMonad m => MWParser m (Attribute Text)
parseAttr

parseAttr :: PandocMonad m => MWParser m (Text, Text)
parseAttr :: forall (m :: * -> *). PandocMonad m => MWParser m (Attribute Text)
parseAttr = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
  Text
k <- forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
letter
  forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'='
  forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
  Text
v <- (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'"' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall end s (m :: * -> *) t st.
(Show end, Stream s m t) =>
ParsecT s st m Char -> ParsecT s st m end -> ParsecT s st m Text
many1TillChar (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (forall a. Eq a => a -> a -> Bool
/=Char
'\n')) (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'"'))
       forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy forall a b. (a -> b) -> a -> b
$ \Char
c -> Bool -> Bool
not (Char -> Bool
isSpace Char
c) Bool -> Bool -> Bool
&& Char
c forall a. Eq a => a -> a -> Bool
/= Char
'|')
  forall (m :: * -> *) a. Monad m => a -> m a
return (Text
k,Text
v)

tableStart :: PandocMonad m => MWParser m ()
tableStart :: forall (m :: * -> *). PandocMonad m => MWParser m ()
tableStart = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => MWParser m ()
guardColumnOne forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
sym Text
"{|"

tableEnd :: PandocMonad m => MWParser m ()
tableEnd :: forall (m :: * -> *). PandocMonad m => MWParser m ()
tableEnd = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => MWParser m ()
guardColumnOne forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
sym Text
"|}"

rowsep :: PandocMonad m => MWParser m ()
rowsep :: forall (m :: * -> *). PandocMonad m => MWParser m ()
rowsep = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => MWParser m ()
guardColumnOne forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
sym Text
"|-" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*
               forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'-') forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional forall (m :: * -> *). PandocMonad m => MWParser m [Attribute Text]
parseAttrs
                               forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
                               forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall (m :: * -> *). PandocMonad m => MWParser m ()
htmlComment
                               forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
blanklines

cellsep :: PandocMonad m => MWParser m ()
cellsep :: forall (m :: * -> *). PandocMonad m => MWParser m ()
cellsep = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Int
col <- SourcePos -> Int
sourceColumn forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
  let pipeSep :: ParsecT Sources u m ()
pipeSep = do
        forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|'
        forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf [Char]
"-}+")
        if Int
col forall a. Eq a => a -> a -> Bool
== Int
1
           then forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|')
           else forall (f :: * -> *) a. Functor f => f a -> f ()
void (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|')
  let exclSep :: ParsecT Sources u m ()
exclSep = do
        forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'!'
        if Int
col forall a. Eq a => a -> a -> Bool
== Int
1
           then forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'!')
           else forall (f :: * -> *) a. Functor f => f a -> f ()
void (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'!')
  forall {u}. ParsecT Sources u m ()
pipeSep forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT Sources u m ()
exclSep

tableCaption :: PandocMonad m => MWParser m Inlines
tableCaption :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
tableCaption = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional forall (m :: * -> *). PandocMonad m => MWParser m ()
rowsep
  forall (m :: * -> *). PandocMonad m => MWParser m ()
guardColumnOne
  forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
  forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
sym Text
"|+"
  forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => MWParser m [Attribute Text]
parseAttrs forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
blanklines)
  Inlines -> Inlines
trimInlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (forall (m :: * -> *). PandocMonad m => MWParser m ()
cellsep forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m ()
rowsep) forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => MWParser m Inlines
inline)

tableRow :: PandocMonad m => MWParser m [(Double, Cell)]
tableRow :: forall (m :: * -> *). PandocMonad m => MWParser m [(Double, Cell)]
tableRow = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall (m :: * -> *). PandocMonad m => MWParser m ()
htmlComment forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall (m :: * -> *). PandocMonad m => MWParser m (Double, Cell)
tableCell

tableCell :: PandocMonad m => MWParser m (Double, Cell)
tableCell :: forall (m :: * -> *). PandocMonad m => MWParser m (Double, Cell)
tableCell = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). PandocMonad m => MWParser m ()
cellsep
  forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
  [Attribute Text]
attribs <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => MWParser m [Attribute Text]
parseAttrs forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*
                                 forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|')
  forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
  SourcePos
pos' <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  Text
ls <- [Text] -> Text
T.concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (forall (m :: * -> *). PandocMonad m => MWParser m ()
cellsep forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m ()
rowsep forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m ()
tableEnd) forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                            ((forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) st a.
Monad m =>
ParsecT Sources st m a -> ParsecT Sources st m (a, Text)
withRaw forall (m :: * -> *). PandocMonad m => MWParser m Blocks
table) forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar))
  Blocks
bs <- forall (m :: * -> *) st r.
Monad m =>
ParsecT Sources st m r -> Text -> ParsecT Sources st m r
parseFromString (do forall (m :: * -> *) s u. Monad m => SourcePos -> ParsecT s u m ()
setPosition SourcePos
pos'
                            forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall (m :: * -> *). PandocMonad m => MWParser m Blocks
block) Text
ls
  let align :: Alignment
align = case forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"align" [Attribute Text]
attribs of
                    Just Text
"left"   -> Alignment
AlignLeft
                    Just Text
"right"  -> Alignment
AlignRight
                    Just Text
"center" -> Alignment
AlignCenter
                    Maybe Text
_             -> Alignment
AlignDefault
  let width :: Double
width = case forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"width" [Attribute Text]
attribs of
                    Just Text
xs -> forall a. a -> Maybe a -> a
fromMaybe Double
0.0 forall a b. (a -> b) -> a -> b
$ Text -> Maybe Double
parseWidth Text
xs
                    Maybe Text
Nothing -> Double
0.0
  let rowspan :: RowSpan
rowspan = Int -> RowSpan
RowSpan forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a -> a
fromMaybe Int
1 forall a b. (a -> b) -> a -> b
$
                forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"rowspan" [Attribute Text]
attribs
  let colspan :: ColSpan
colspan = Int -> ColSpan
ColSpan forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a -> a
fromMaybe Int
1 forall a b. (a -> b) -> a -> b
$
                forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"colspan" [Attribute Text]
attribs
  let handledAttribs :: [Text]
handledAttribs = [Text
"align", Text
"colspan", Text
"rowspan"]
      attribs' :: [Attribute Text]
attribs' = [ (Text
k, Text
v) | (Text
k, Text
v) <- [Attribute Text]
attribs
                          , Text
k forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Text]
handledAttribs
                 ]
  forall (m :: * -> *) a. Monad m => a -> m a
return (Double
width, Attr -> Alignment -> RowSpan -> ColSpan -> Blocks -> Cell
B.cellWith ([Attribute Text] -> Attr
toAttr [Attribute Text]
attribs') Alignment
align RowSpan
rowspan ColSpan
colspan Blocks
bs)

parseWidth :: Text -> Maybe Double
parseWidth :: Text -> Maybe Double
parseWidth Text
s =
  case Text -> Maybe (Text, Char)
T.unsnoc Text
s of
    Just (Text
ds, Char
'%') | (Char -> Bool) -> Text -> Bool
T.all Char -> Bool
isDigit Text
ds -> forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead forall a b. (a -> b) -> a -> b
$ Text
"0." forall a. Semigroup a => a -> a -> a
<> Text
ds
    Maybe (Text, Char)
_ -> forall a. Maybe a
Nothing

template :: PandocMonad m => MWParser m Text
template :: forall (m :: * -> *). PandocMonad m => MWParser m Text
template = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"{{"
  forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'{')
  forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
letter forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
digit forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
':'
  let chunk :: ParsecT Sources MWState m Text
chunk = forall (m :: * -> *). PandocMonad m => MWParser m Text
template forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Text
variable forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"{}") forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar
  [Text]
contents <- forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Sources MWState m Text
chunk (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"}}")
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"{{" forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
T.concat [Text]
contents forall a. Semigroup a => a -> a -> a
<> Text
"}}"

blockTag :: PandocMonad m => MWParser m Blocks
blockTag :: forall (m :: * -> *). PandocMonad m => MWParser m Blocks
blockTag = do
  (Tag Text
tag, Text
_) <- forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall a b. (a -> b) -> a -> b
$ forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag Tag Text -> Bool
isBlockTag'
  case Tag Text
tag of
      TagOpen Text
"blockquote" [Attribute Text]
_ -> Blocks -> Blocks
B.blockQuote forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> MWParser m Blocks
blocksInTags Text
"blockquote"
      TagOpen Text
"pre" [Attribute Text]
_ -> Text -> Blocks
B.codeBlock forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
trimCode forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> MWParser m Text
textInTags Text
"pre"
      TagOpen Text
"syntaxhighlight" [Attribute Text]
attrs -> forall (m :: * -> *).
PandocMonad m =>
Text -> [Attribute Text] -> MWParser m Blocks
syntaxhighlight Text
"syntaxhighlight" [Attribute Text]
attrs
      TagOpen Text
"source" [Attribute Text]
attrs -> forall (m :: * -> *).
PandocMonad m =>
Text -> [Attribute Text] -> MWParser m Blocks
syntaxhighlight Text
"source" [Attribute Text]
attrs
      TagOpen Text
"haskell" [Attribute Text]
_ -> Attr -> Text -> Blocks
B.codeBlockWith (Text
"",[Text
"haskell"],[]) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
trimCode forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
                                forall (m :: * -> *). PandocMonad m => Text -> MWParser m Text
textInTags Text
"haskell"
      TagOpen Text
"gallery" [Attribute Text]
_ -> forall (m :: * -> *). PandocMonad m => Text -> MWParser m Blocks
blocksInTags Text
"gallery"
      TagOpen Text
"p" [Attribute Text]
_ -> forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== Tag Text
tag)
      TagClose Text
"p"  -> forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== Tag Text
tag)
      Tag Text
_ -> Text -> Text -> Blocks
B.rawBlock Text
"html" forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== Tag Text
tag)

trimCode :: Text -> Text
trimCode :: Text -> Text
trimCode Text
t = case Text -> Maybe (Char, Text)
T.uncons Text
t of
  Just (Char
'\n', Text
xs) -> Text -> Text
stripTrailingNewlines Text
xs
  Maybe (Char, Text)
_               -> Text -> Text
stripTrailingNewlines Text
t

syntaxhighlight :: PandocMonad m => Text -> [Attribute Text] -> MWParser m Blocks
syntaxhighlight :: forall (m :: * -> *).
PandocMonad m =>
Text -> [Attribute Text] -> MWParser m Blocks
syntaxhighlight Text
tag [Attribute Text]
attrs = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  let mblang :: Maybe Text
mblang = forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"lang" [Attribute Text]
attrs
  let mbstart :: Maybe Text
mbstart = forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"start" [Attribute Text]
attrs
  let mbline :: Maybe Text
mbline = forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"line" [Attribute Text]
attrs
  let classes :: [Text]
classes = forall a. Maybe a -> [a]
maybeToList Maybe Text
mblang forall a. [a] -> [a] -> [a]
++ forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (forall a b. a -> b -> a
const [Text
"numberLines"]) Maybe Text
mbline
  let kvs :: [Attribute Text]
kvs = forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Text
x -> [(Text
"startFrom",Text
x)]) Maybe Text
mbstart
  Text
contents <- forall (m :: * -> *). PandocMonad m => Text -> MWParser m Text
textInTags Text
tag
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Blocks
B.codeBlockWith (Text
"",[Text]
classes,[Attribute Text]
kvs) forall a b. (a -> b) -> a -> b
$ Text -> Text
trimCode Text
contents

hrule :: PandocMonad m => MWParser m Blocks
hrule :: forall (m :: * -> *). PandocMonad m => MWParser m Blocks
hrule = Blocks
B.horizontalRule forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"----" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'-') forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline)

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

preformatted :: PandocMonad m => MWParser m Blocks
preformatted :: forall (m :: * -> *). PandocMonad m => MWParser m Blocks
preformatted = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). PandocMonad m => MWParser m ()
guardColumnOne
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
' '
  let endline' :: ParsecT Sources u m Inlines
endline' = Inlines
B.linebreak forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
' ')
  let whitespace' :: ParsecT Sources st m Inlines
whitespace' = Text -> Inlines
B.str forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char (Char
'\160' forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar)
  let spToNbsp :: Char -> Char
spToNbsp Char
' ' = Char
'\160'
      spToNbsp Char
x   = Char
x
  let nowiki' :: ParsecT Sources MWState m Inlines
nowiki' = forall a. Monoid a => [a] -> a
mconcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> [a] -> [a]
intersperse Inlines
B.linebreak forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map Text -> Inlines
B.str forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                Text -> [Text]
T.lines forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
fromEntities forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Char) -> Text -> Text
T.map Char -> Char
spToNbsp forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try
                  (forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> [Attribute str] -> Tag str
TagOpen (Text
"nowiki" :: Text) []) forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                   forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> Tag str
TagClose (Text
"nowiki" :: Text))))
  let inline' :: ParsecT Sources MWState m Inlines
inline' = forall {st}. ParsecT Sources st m Inlines
whitespace' forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {st}. ParsecT Sources st m Inlines
endline' forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources MWState m Inlines
nowiki'
                  forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => MWParser m Inlines
inline)
  Inlines
contents <- forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources MWState m Inlines
inline'
  let spacesStr :: Inline -> Bool
spacesStr (Str Text
xs) = (Char -> Bool) -> Text -> Bool
T.all Char -> Bool
isSpace Text
xs
      spacesStr Inline
_        = Bool
False
  if forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
F.all Inline -> Bool
spacesStr Inlines
contents
     then forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
     else forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
B.para forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
encode Inlines
contents

encode :: Inlines -> Inlines
encode :: Inlines -> Inlines
encode = Attr -> Inlines -> Inlines
formatCode Attr
nullAttr

header :: PandocMonad m => MWParser m Blocks
header :: forall (m :: * -> *). PandocMonad m => MWParser m Blocks
header = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). PandocMonad m => MWParser m ()
guardColumnOne
  Int
lev <- forall (t :: * -> *) a. Foldable t => t a -> Int
length forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'=')
  forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ Int
lev forall a. Ord a => a -> a -> Bool
<= Int
6
  Inlines
contents <- Inlines -> Inlines
trimInlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => MWParser m Inlines
inline (forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
lev forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'=')
  ReaderOptions
opts <- MWState -> ReaderOptions
mwOptions forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Attr
attr <- (if forall a. HasSyntaxExtensions a => Extension -> a -> Bool
isEnabled Extension
Ext_gfm_auto_identifiers ReaderOptions
opts
              then forall a. a -> a
id
              else Attr -> Attr
modifyIdentifier) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st, HasLogMessages st,
 HasIdentifierList st) =>
Attr -> Inlines -> ParsecT s st m Attr
registerHeader Attr
nullAttr Inlines
contents
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> Int -> Inlines -> Blocks
B.headerWith Attr
attr Int
lev Inlines
contents

-- See #4731:
modifyIdentifier :: Attr -> Attr
modifyIdentifier :: Attr -> Attr
modifyIdentifier (Text
ident,[Text]
cl,[Attribute Text]
kv) = (Text
ident',[Text]
cl,[Attribute Text]
kv)
  where ident' :: Text
ident' = (Char -> Char) -> Text -> Text
T.map (\Char
c -> if Char
c forall a. Eq a => a -> a -> Bool
== Char
'-' then Char
'_' else Char
c) Text
ident

bulletList :: PandocMonad m => MWParser m Blocks
bulletList :: forall (m :: * -> *). PandocMonad m => MWParser m Blocks
bulletList = [Blocks] -> Blocks
B.bulletList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
   (   forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall (m :: * -> *). PandocMonad m => Char -> MWParser m Blocks
listItem Char
'*')
   forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> [Attribute str] -> Tag str
TagOpen (Text
"ul" :: Text) []) forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall (m :: * -> *). PandocMonad m => Char -> MWParser m Blocks
listItem Char
'*' forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Blocks
li) forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*
        forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> Tag str
TagClose (Text
"ul" :: Text)))) )

orderedList :: PandocMonad m => MWParser m Blocks
orderedList :: forall (m :: * -> *). PandocMonad m => MWParser m Blocks
orderedList =
       ([Blocks] -> Blocks
B.orderedList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall (m :: * -> *). PandocMonad m => Char -> MWParser m Blocks
listItem Char
'#'))
   forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try
       (do (Tag Text
tag,Text
_) <- forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> [Attribute str] -> Tag str
TagOpen (Text
"ol" :: Text) [])
           forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces
           [Blocks]
items <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall (m :: * -> *). PandocMonad m => Char -> MWParser m Blocks
listItem Char
'#' forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Blocks
li)
           forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> Tag str
TagClose (Text
"ol" :: Text)))
           let start :: Int
start = forall a. a -> Maybe a -> a
fromMaybe Int
1 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead forall a b. (a -> b) -> a -> b
$ forall str.
(Show str, Eq str, StringLike str) =>
str -> Tag str -> str
fromAttrib Text
"start" Tag Text
tag
           forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ListAttributes -> [Blocks] -> Blocks
B.orderedListWith (Int
start, ListNumberStyle
DefaultStyle, ListNumberDelim
DefaultDelim) [Blocks]
items)

definitionList :: PandocMonad m => MWParser m Blocks
definitionList :: forall (m :: * -> *). PandocMonad m => MWParser m Blocks
definitionList = [(Inlines, [Blocks])] -> Blocks
B.definitionList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall (m :: * -> *).
PandocMonad m =>
MWParser m (Inlines, [Blocks])
defListItem

defListItem :: PandocMonad m => MWParser m (Inlines, [Blocks])
defListItem :: forall (m :: * -> *).
PandocMonad m =>
MWParser m (Inlines, [Blocks])
defListItem = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Inlines
terms <- forall a. Monoid a => [a] -> a
mconcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> [a] -> [a]
intersperse Inlines
B.linebreak forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall (m :: * -> *). PandocMonad m => MWParser m Inlines
defListTerm
  -- we allow dd with no dt, or dt with no dd
  [Blocks]
defs  <- if forall (t :: * -> *) a. Foldable t => t a -> Bool
null Inlines
terms
              then forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy
                    (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
':') forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"<math>") forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                       forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall (m :: * -> *). PandocMonad m => Char -> MWParser m Blocks
listItem Char
':')
              else forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall (m :: * -> *). PandocMonad m => Char -> MWParser m Blocks
listItem Char
':')
  forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines
terms, [Blocks]
defs)

defListTerm  :: PandocMonad m => MWParser m Inlines
defListTerm :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
defListTerm = do
  forall (m :: * -> *). PandocMonad m => MWParser m ()
guardColumnOne
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
';'
  forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
  SourcePos
pos' <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLine forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) st r.
Monad m =>
ParsecT Sources st m r -> Text -> ParsecT Sources st m r
parseFromString (do forall (m :: * -> *) s u. Monad m => SourcePos -> ParsecT s u m ()
setPosition SourcePos
pos'
                                  Inlines -> Inlines
trimInlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall (m :: * -> *). PandocMonad m => MWParser m Inlines
inline)

listStart :: PandocMonad m => Char -> MWParser m ()
listStart :: forall (m :: * -> *). PandocMonad m => Char -> MWParser m ()
listStart Char
c = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy forall (m :: * -> *). PandocMonad m => MWParser m Char
listStartChar

listStartChar :: PandocMonad m => MWParser m Char
listStartChar :: forall (m :: * -> *). PandocMonad m => MWParser m Char
listStartChar = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf [Char]
"*#;:"

anyListStart :: PandocMonad m => MWParser m Char
anyListStart :: forall (m :: * -> *). PandocMonad m => MWParser m Char
anyListStart = forall (m :: * -> *). PandocMonad m => MWParser m ()
guardColumnOne forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf [Char]
"*#:;"

li :: PandocMonad m => MWParser m Blocks
li :: forall (m :: * -> *). PandocMonad m => MWParser m Blocks
li = forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> [Attribute str] -> Tag str
TagOpen (Text
"li" :: Text) [])) forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
     (Blocks -> Blocks
firstParaToPlain forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> MWParser m Blocks
blocksInTags Text
"li") forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces

listItem :: PandocMonad m => Char -> MWParser m Blocks
listItem :: forall (m :: * -> *). PandocMonad m => Char -> MWParser m Blocks
listItem Char
c = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). PandocMonad m => MWParser m ()
guardColumnOne
  [Char]
extras <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall (m :: * -> *). PandocMonad m => MWParser m Char
listStartChar)
  if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
extras
     then forall (m :: * -> *). PandocMonad m => Char -> MWParser m Blocks
listItem' Char
c
     else do
       forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
       SourcePos
pos' <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
       Text
first <- [Text] -> Text
T.concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => MWParser m Text
listChunk forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
       [Text]
rest <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many
                (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
extras forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall (m :: * -> *). PandocMonad m => MWParser m Char
listStartChar forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                       ([Text] -> Text
T.concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => MWParser m Text
listChunk forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline))
       [Blocks]
contents <- forall (m :: * -> *) st r.
Monad m =>
ParsecT Sources st m r -> Text -> ParsecT Sources st m r
parseFromString (do forall (m :: * -> *) s u. Monad m => SourcePos -> ParsecT s u m ()
setPosition SourcePos
pos'
                                       forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => Char -> MWParser m Blocks
listItem' Char
c)
                          ([Text] -> Text
T.unlines (Text
first forall a. a -> [a] -> [a]
: [Text]
rest))
       case Char
c of
           Char
'*' -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [Blocks] -> Blocks
B.bulletList [Blocks]
contents
           Char
'#' -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [Blocks] -> Blocks
B.orderedList [Blocks]
contents
           Char
':' -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [(Inlines, [Blocks])] -> Blocks
B.definitionList [(forall a. Monoid a => a
mempty, [Blocks]
contents)]
           Char
_   -> forall (m :: * -> *) a. MonadPlus m => m a
mzero

-- The point of this is to handle stuff like
-- * {{cite book
-- | blah
-- | blah
-- }}
-- * next list item
-- which seems to be valid mediawiki.
listChunk :: PandocMonad m => MWParser m Text
listChunk :: forall (m :: * -> *). PandocMonad m => MWParser m Text
listChunk = forall (m :: * -> *). PandocMonad m => MWParser m Text
template forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar

listItem' :: PandocMonad m => Char -> MWParser m Blocks
listItem' :: forall (m :: * -> *). PandocMonad m => Char -> MWParser m Blocks
listItem' Char
c = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). PandocMonad m => Char -> MWParser m ()
listStart Char
c
  forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
  SourcePos
pos' <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  Text
first <- [Text] -> Text
T.concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => MWParser m Text
listChunk forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
  [Text]
rest <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall (m :: * -> *). PandocMonad m => MWParser m Char
listStartChar forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                   ([Text] -> Text
T.concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => MWParser m Text
listChunk forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline))
  forall (m :: * -> *) st r.
Monad m =>
ParsecT Sources st m r -> Text -> ParsecT Sources st m r
parseFromString (do forall (m :: * -> *) s u. Monad m => SourcePos -> ParsecT s u m ()
setPosition SourcePos
pos'
                      Blocks -> Blocks
firstParaToPlain forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall (m :: * -> *). PandocMonad m => MWParser m Blocks
block)
      forall a b. (a -> b) -> a -> b
$ [Text] -> Text
T.unlines forall a b. (a -> b) -> a -> b
$ Text
first forall a. a -> [a] -> [a]
: [Text]
rest

firstParaToPlain :: Blocks -> Blocks
firstParaToPlain :: Blocks -> Blocks
firstParaToPlain Blocks
contents =
  case forall a. Seq a -> ViewL a
viewl (forall a. Many a -> Seq a
B.unMany Blocks
contents) of
       Para [Inline]
xs :< Seq Block
ys -> forall a. Seq a -> Many a
B.Many forall a b. (a -> b) -> a -> b
$ [Inline] -> Block
Plain [Inline]
xs forall a. a -> Seq a -> Seq a
<| Seq Block
ys
       ViewL Block
_             -> Blocks
contents

--
-- inline parsers
--

inline :: PandocMonad m => MWParser m Inlines
inline :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
inline =  forall (m :: * -> *). PandocMonad m => MWParser m Inlines
whitespace
      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Inlines
url
      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Inlines
str
      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Inlines
doubleQuotes
      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Inlines
strong
      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Inlines
emph
      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Inlines
image
      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Inlines
internalLink
      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Inlines
externalLink
      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Inlines
math
      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Inlines
inlineTag
      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall a. a -> Many a
B.singleton forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Inline
charRef
      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Inlines
inlineHtml
      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Text -> Text -> Inlines
B.rawInline Text
"mediawiki" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => MWParser m Text
variable)
      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Text -> Text -> Inlines
B.rawInline Text
"mediawiki" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => MWParser m Text
template)
      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m Inlines
special

str :: PandocMonad m => MWParser m Inlines
str :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
str = Text -> Inlines
B.str forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf forall a b. (a -> b) -> a -> b
$ [Char]
specialChars forall a. [a] -> [a] -> [a]
++ [Char]
spaceChars)

math :: PandocMonad m => MWParser m Inlines
math :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
math = (Text -> Inlines
B.displayMath forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
trim forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
':') forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => Text -> MWParser m Text
textInTags Text
"math"))
   forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Text -> Inlines
B.math forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
trim forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> MWParser m Text
textInTags Text
"math")
   forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Text -> Inlines
B.displayMath forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
trim forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall {u}. ParsecT Sources u m [Char]
dmStart forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar forall {u}. ParsecT Sources u m [Char]
dmEnd))
   forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Text -> Inlines
B.math forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
trim forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall {u}. ParsecT Sources u m [Char]
mStart forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (forall a. Eq a => a -> a -> Bool
/=Char
'\n')) forall {u}. ParsecT Sources u m [Char]
mEnd))
 where dmStart :: ParsecT Sources u m [Char]
dmStart = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"\\["
       dmEnd :: ParsecT Sources u m [Char]
dmEnd   = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"\\]")
       mStart :: ParsecT Sources u m [Char]
mStart  = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"\\("
       mEnd :: ParsecT Sources u m [Char]
mEnd    = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"\\)")

variable :: PandocMonad m => MWParser m Text
variable :: forall (m :: * -> *). PandocMonad m => MWParser m Text
variable = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"{{{"
  Text
contents <- forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"}}}")
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"{{{" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"}}}"

singleParaToPlain :: Blocks -> Blocks
singleParaToPlain :: Blocks -> Blocks
singleParaToPlain Blocks
bs =
  case forall a. Many a -> [a]
B.toList Blocks
bs of
    [Para [Inline]
ils] -> forall a. [a] -> Many a
B.fromList [[Inline] -> Block
Plain [Inline]
ils]
    [Block]
_ -> Blocks
bs

inlineTag :: PandocMonad m => MWParser m Inlines
inlineTag :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
inlineTag = do
  (Tag Text
tag, Text
_) <- forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall a b. (a -> b) -> a -> b
$ forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag Tag Text -> Bool
isInlineTag'
  case Tag Text
tag of
       TagOpen Text
"ref" [Attribute Text]
_ -> Blocks -> Inlines
B.note forall b c a. (b -> c) -> (a -> b) -> a -> c
. Blocks -> Blocks
singleParaToPlain forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> MWParser m Blocks
blocksInTags Text
"ref"
       TagOpen Text
"nowiki" [Attribute Text]
_ -> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
          (Tag Text
_,Text
raw) <- forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== Tag Text
tag)
          if (Char -> Bool) -> Text -> Bool
T.any (forall a. Eq a => a -> a -> Bool
== Char
'/') Text
raw
             then forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
             else Text -> Inlines
B.text forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
fromEntities forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
                       forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> Tag str
TagClose (Text
"nowiki" :: Text)))
       TagOpen Text
"br" [Attribute Text]
_ -> Inlines
B.linebreak forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== forall str. str -> [Attribute str] -> Tag str
TagOpen (Text
"br" :: Text) []) -- will get /> too
                            forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline)
       TagOpen Text
"strike" [Attribute Text]
_ -> Inlines -> Inlines
B.strikeout forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> MWParser m Inlines
inlinesInTags Text
"strike"
       TagOpen Text
"del" [Attribute Text]
_ -> Inlines -> Inlines
B.strikeout forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> MWParser m Inlines
inlinesInTags Text
"del"
       TagOpen Text
"sub" [Attribute Text]
_ -> Inlines -> Inlines
B.subscript forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> MWParser m Inlines
inlinesInTags Text
"sub"
       TagOpen Text
"sup" [Attribute Text]
_ -> Inlines -> Inlines
B.superscript forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> MWParser m Inlines
inlinesInTags Text
"sup"
       TagOpen Text
"code" [Attribute Text]
_ -> Inlines -> Inlines
encode forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> MWParser m Inlines
inlinesInTags Text
"code"
       TagOpen Text
"tt" [Attribute Text]
_ -> do
         Bool
inTT <- MWState -> Bool
mwInTT forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
         forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \MWState
st -> MWState
st{ mwInTT :: Bool
mwInTT = Bool
True }
         Inlines
result <- Inlines -> Inlines
encode forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> MWParser m Inlines
inlinesInTags Text
"tt"
         forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \MWState
st -> MWState
st{ mwInTT :: Bool
mwInTT = Bool
inTT }
         forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
result
       TagOpen Text
"hask" [Attribute Text]
_ -> Attr -> Text -> Inlines
B.codeWith (Text
"",[Text
"haskell"],[]) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> MWParser m Text
textInTags Text
"hask"
       Tag Text
_ -> Text -> Text -> Inlines
B.rawInline Text
"html" forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== Tag Text
tag)

special :: PandocMonad m => MWParser m Inlines
special :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
special = Text -> Inlines
B.str forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 (forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' (forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag Tag Text -> Bool
isBlockTag') forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                                  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf [Char]
specialChars)

inlineHtml :: PandocMonad m => MWParser m Inlines
inlineHtml :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
inlineHtml = Text -> Text -> Inlines
B.rawInline Text
"html" forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag Tag Text -> Bool
isInlineTag'

whitespace :: PandocMonad m => MWParser m Inlines
whitespace :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
whitespace = Inlines
B.space forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => MWParser m ()
htmlComment)
         forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Inlines
B.softbreak forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => MWParser m ()
endline

endline :: PandocMonad m => MWParser m ()
endline :: forall (m :: * -> *). PandocMonad m => MWParser m ()
endline = () forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*
                     forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*
                     forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*
                     forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' forall (m :: * -> *). PandocMonad m => MWParser m Blocks
hrule forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*
                     forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy forall (m :: * -> *). PandocMonad m => MWParser m ()
tableStart forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*
                     forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' forall (m :: * -> *). PandocMonad m => MWParser m Blocks
header forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*
                     forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy forall (m :: * -> *). PandocMonad m => MWParser m Char
anyListStart)

imageIdentifiers :: PandocMonad m => [MWParser m ()]
imageIdentifiers :: forall (m :: * -> *). PandocMonad m => [MWParser m ()]
imageIdentifiers = [forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
sym (Text
identifier forall a. Semigroup a => a -> a -> a
<> Text
":") | Text
identifier <- [Text]
identifiers]
    where identifiers :: [Text]
identifiers = [Text
"File", Text
"Image", Text
"Archivo", Text
"Datei", Text
"Fichier",
                         Text
"Bild"]

image :: PandocMonad m => MWParser m Inlines
image :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
image = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
sym Text
"[["
  forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice forall (m :: * -> *). PandocMonad m => [MWParser m ()]
imageIdentifiers
  Text
fname <- Text -> Text
addUnderscores forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"|]")
  [Text]
_ <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall (m :: * -> *). PandocMonad m => MWParser m Text
imageOption
  [Text]
dims <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
sepBy (forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
manyChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
digit) (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'x') forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"px")
          forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) a. Monad m => a -> m a
return []
  [Text]
_ <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall (m :: * -> *). PandocMonad m => MWParser m Text
imageOption
  let kvs :: [Attribute Text]
kvs = case [Text]
dims of
              [Text
w]    -> [(Text
"width", Text
w)]
              [Text
w, Text
h] -> [(Text
"width", Text
w), (Text
"height", Text
h)]
              [Text]
_      -> []
  let attr :: (Text, [a], [Attribute Text])
attr = (Text
"", [], [Attribute Text]
kvs)
  Inlines
caption <-   (Text -> Inlines
B.str Text
fname forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
sym Text
"]]")
           forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => MWParser m Inlines
inline (forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
sym Text
"]]")))
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Text -> Inlines -> Inlines
B.imageWith forall {a}. (Text, [a], [Attribute Text])
attr Text
fname (forall a. Walkable Inline a => a -> Text
stringify Inlines
caption) Inlines
caption

imageOption :: PandocMonad m => MWParser m Text
imageOption :: forall (m :: * -> *). PandocMonad m => MWParser m Text
imageOption = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall {u}. ParsecT Sources u m Text
opt
  where
    opt :: ParsecT Sources u m Text
opt = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
[Text] -> ParsecT s st m Text
oneOfStrings [ Text
"border", Text
"thumbnail", Text
"frameless"
                            , Text
"thumb", Text
"upright", Text
"left", Text
"right"
                            , Text
"center", Text
"none", Text
"baseline", Text
"sub"
                            , Text
"super", Text
"top", Text
"text-top", Text
"middle"
                            , Text
"bottom", Text
"text-bottom" ])
      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
"frame")
      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
[Text] -> ParsecT s st m Text
oneOfStrings [Text
"link=",Text
"alt=",Text
"page=",Text
"class="] forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"|]"))

addUnderscores :: Text -> Text
addUnderscores :: Text -> Text
addUnderscores = Text -> [Text] -> Text
T.intercalate Text
"_" forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> [Text]
splitTextBy Char -> Bool
sep
  where
    sep :: Char -> Bool
sep Char
c = Char -> Bool
isSpace Char
c Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'_'

internalLink :: PandocMonad m => MWParser m Inlines
internalLink :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
internalLink = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
sym Text
"[["
  Text
pagename <- [Text] -> Text
T.unwords forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Text]
T.words forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
manyChar (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"|]")
  Inlines
label <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (Text -> Inlines
B.text Text
pagename) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
             (  (forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']') forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => MWParser m Inlines
inline))
             -- the "pipe trick"
             -- [[Help:Contents|] -> "Contents"
             forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Inlines
B.text forall a b. (a -> b) -> a -> b
$ Int -> Text -> Text
T.drop Int
1 forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Text
T.dropWhile (forall a. Eq a => a -> a -> Bool
/=Char
':') Text
pagename) )
  forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
sym Text
"]]"
  -- see #8525:
  Inlines
linktrail <- Text -> Inlines
B.text forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
manyChar (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (\Char
c -> Char -> Bool
isLetter Char
c Bool -> Bool -> Bool
&& Bool -> Bool
not (Char -> Bool
isCJK Char
c)))
  let link :: Inlines
link = Text -> Text -> Inlines -> Inlines
B.link (Text -> Text
addUnderscores Text
pagename) Text
"wikilink" (Inlines
label forall a. Semigroup a => a -> a -> a
<> Inlines
linktrail)
  if Text
"Category:" Text -> Text -> Bool
`T.isPrefixOf` Text
pagename
     then do
       forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \MWState
st -> MWState
st{ mwCategoryLinks :: [Inlines]
mwCategoryLinks = Inlines
link forall a. a -> [a] -> [a]
: MWState -> [Inlines]
mwCategoryLinks MWState
st }
       forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
     else forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
link

isCJK :: Char -> Bool
isCJK :: Char -> Bool
isCJK Char
c =
  (Char
c forall a. Ord a => a -> a -> Bool
>= Char
'\x3400' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'\x4DBF') Bool -> Bool -> Bool
||
  (Char
c forall a. Ord a => a -> a -> Bool
>= Char
'\x4E00' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'\x9FFF') Bool -> Bool -> Bool
||
  (Char
c forall a. Ord a => a -> a -> Bool
>= Char
'\x20000' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'\x2A6DF') Bool -> Bool -> Bool
||
  (Char
c forall a. Ord a => a -> a -> Bool
>= Char
'\x2A700' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'\x2B73F') Bool -> Bool -> Bool
||
  (Char
c forall a. Ord a => a -> a -> Bool
>= Char
'\x2B740' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'\x2B81F') Bool -> Bool -> Bool
||
  (Char
c forall a. Ord a => a -> a -> Bool
>= Char
'\x2B820' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'\x2CEAF') Bool -> Bool -> Bool
||
  (Char
c forall a. Ord a => a -> a -> Bool
>= Char
'\x2CEB0' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'\x2EBEF') Bool -> Bool -> Bool
||
  (Char
c forall a. Ord a => a -> a -> Bool
>= Char
'\x30000' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'\x3134F') Bool -> Bool -> Bool
||
  (Char
c forall a. Ord a => a -> a -> Bool
>= Char
'\x31350' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'\x323AF') Bool -> Bool -> Bool
||
  (Char
c forall a. Ord a => a -> a -> Bool
>= Char
'\xF900' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'\xFAFF') Bool -> Bool -> Bool
||
  (Char
c forall a. Ord a => a -> a -> Bool
>= Char
'\x2F800' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'\x2FA1F') Bool -> Bool -> Bool
||
  (Char
c forall a. Ord a => a -> a -> Bool
>= Char
'\x2F00' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'\x2FDF') Bool -> Bool -> Bool
||
  (Char
c forall a. Ord a => a -> a -> Bool
>= Char
'\x2E80' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'\x2EFF') Bool -> Bool -> Bool
||
  (Char
c forall a. Ord a => a -> a -> Bool
>= Char
'\x3000' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'\x303F')

externalLink :: PandocMonad m => MWParser m Inlines
externalLink :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
externalLink = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'['
  (Text
_, Text
src) <- forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (Attribute Text)
uri
  Inlines
lab <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Inlines -> Inlines
trimInlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
              (forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => MWParser m Inlines
inline (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']')))
       forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> do forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']'
              Int
num <- MWState -> Int
mwNextLinkNumber forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
              forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \MWState
st -> MWState
st{ mwNextLinkNumber :: Int
mwNextLinkNumber = Int
num forall a. Num a => a -> a -> a
+ Int
1 }
              forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> Text
tshow Int
num
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.link Text
src Text
"" Inlines
lab

url :: PandocMonad m => MWParser m Inlines
url :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
url = do
  (Text
orig, Text
src) <- forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (Attribute Text)
uri
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.link Text
src Text
"" (Text -> Inlines
B.str Text
orig)

-- | Parses a list of inlines between start and end delimiters.
inlinesBetween :: (PandocMonad m, Show b) => MWParser m a -> MWParser m b -> MWParser m Inlines
inlinesBetween :: forall (m :: * -> *) b a.
(PandocMonad m, Show b) =>
MWParser m a -> MWParser m b -> MWParser m Inlines
inlinesBetween MWParser m a
start MWParser m b
end =
  Inlines -> Inlines
trimInlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MWParser m a
start forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
many1Till forall (m :: * -> *). PandocMonad m => MWParser m Inlines
inline MWParser m b
end)

emph :: PandocMonad m => MWParser m Inlines
emph :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
emph = Inlines -> Inlines
B.emph forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) b a.
(PandocMonad m, Show b) =>
MWParser m a -> MWParser m b -> MWParser m Inlines
inlinesBetween MWParser m ()
start MWParser m ()
end
    where start :: MWParser m ()
start = forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
sym Text
"''"
          end :: MWParser m ()
end   = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' (() forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => MWParser m Inlines
strong) forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
sym Text
"''"

strong :: PandocMonad m => MWParser m Inlines
strong :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
strong = Inlines -> Inlines
B.strong forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) b a.
(PandocMonad m, Show b) =>
MWParser m a -> MWParser m b -> MWParser m Inlines
inlinesBetween MWParser m ()
start MWParser m ()
end
    where start :: MWParser m ()
start = forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
sym Text
"'''"
          end :: MWParser m ()
end   = forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
sym Text
"'''"

doubleQuotes :: PandocMonad m => MWParser m Inlines
doubleQuotes :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
doubleQuotes = do
  forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_smart
  Bool
inTT <- MWState -> Bool
mwInTT forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not Bool
inTT)
  Inlines -> Inlines
B.doubleQuoted forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) b a.
(PandocMonad m, Show b) =>
MWParser m a -> MWParser m b -> MWParser m Inlines
inlinesBetween ParsecT Sources MWState m Char
openDoubleQuote ParsecT Sources MWState m ()
closeDoubleQuote
    where openDoubleQuote :: ParsecT Sources MWState m Char
openDoubleQuote = forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
sym Text
"\"" forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
nonspaceChar
          closeDoubleQuote :: ParsecT Sources MWState m ()
closeDoubleQuote = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
sym Text
"\""