    {-# LANGUAGE OverloadedStrings #-}
    {- |
       Module      : Text.Pandoc.Readers.MediaWiki
       Copyright   : Copyright (C) 2012-2024 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.Char (isCJK)
    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 = a -> Sources
    forall a. ToSources a => a -> Sources
    toSources a
    s
      parsed <- ParsecT Sources MWState m Pandoc
    -> MWState -> Sources -> m (Either PandocError Pandoc)
    forall (m :: * -> *) t st a.
    (Monad m, ToSources t) =>
    ParsecT Sources st m a -> st -> t -> m (Either PandocError a)
    readWithM ParsecT Sources MWState m Pandoc
    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 = Set Text
    forall a. Set a
    Set.empty
                                                , mwLogMessages :: [LogMessage]
    mwLogMessages = []
                                                , mwInTT :: Bool
    mwInTT = Bool
    False
                                                , mwAllowNewlines :: Bool
    mwAllowNewlines = Bool
    True
                                                }
                Sources
    sources
      case parsed of
        Right Pandoc
    result -> Pandoc -> m Pandoc
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Pandoc
    result
        Left PandocError
    e       -> PandocError -> m Pandoc
    forall a. PandocError -> m a
    forall e (m :: * -> *) a. MonadError e m => e -> m a
    throwError PandocError
    e

    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
                           , MWState -> Bool
    mwAllowNewlines   :: 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 = f $ mwIdentifierList st }

    instance HasLogMessages MWState where
      addLogMessage :: LogMessage -> MWState -> MWState
    addLogMessage LogMessage
    m MWState
    s = MWState
    s{ mwLogMessages = m : mwLogMessages s }
      getLogMessages :: MWState -> [LogMessage]
    getLogMessages = [LogMessage] -> [LogMessage]
    forall a. [a] -> [a]
    reverse ([LogMessage] -> [LogMessage])
    -> (MWState -> [LogMessage]) -> MWState -> [LogMessage]
    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 = () ()
    -> ParsecT Sources MWState m [Char] -> ParsecT Sources MWState m ()
    forall a b.
    a -> ParsecT Sources MWState m b -> ParsecT Sources MWState m a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Sources MWState m [Char]
    -> ParsecT Sources MWState m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ([Char] -> ParsecT Sources MWState m [Char]
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m [Char]
    string ([Char] -> ParsecT Sources MWState m [Char])
    -> [Char] -> ParsecT Sources MWState m [Char]
    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 Text -> [Text] -> Bool
    forall a. Eq a => a -> [a] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` [Text]
    newBlockTags) Bool -> Bool -> Bool
    &&
      Text
    t Text -> [Text] -> Bool
    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 Text -> [Text] -> Bool
    forall a. Eq a => a -> [a] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` [Text]
    newBlockTags) Bool -> Bool -> Bool
    &&
      Text
    t Text -> [Text] -> Bool
    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 = () ()
    -> ParsecT Sources MWState m (Tag Text, Text)
    -> ParsecT Sources MWState m ()
    forall a b.
    a -> ParsecT Sources MWState m b -> ParsecT Sources MWState m a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ (Tag Text -> Bool) -> ParsecT Sources MWState m (Tag Text, Text)
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    (Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
    htmlTag Tag Text -> Bool
    isCommentTag

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

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

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

    --
    -- main parser
    --

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

    --
    -- block parsers
    --

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

    para :: PandocMonad m => MWParser m Blocks
    para :: forall (m :: * -> *). PandocMonad m => MWParser m Blocks
    para = do
      contents <- Inlines -> Inlines
    trimInlines (Inlines -> Inlines)
    -> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Inlines] -> Inlines
    forall a. Monoid a => [a] -> a
    mconcat ([Inlines] -> Inlines)
    -> ParsecT Sources MWState m [Inlines]
    -> ParsecT Sources MWState m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m [Inlines]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Sources MWState m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    inline
      if F.all (==Space) contents
         then return mempty
         else case B.toList contents of
             -- For the MediaWiki format all images are considered figures
             [Image Attr
    attr [Inline]
    figureCaption (Text
    src, Text
    title)] ->
                 Blocks -> ParsecT Sources MWState m Blocks
    forall a. a -> ParsecT Sources MWState m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> ParsecT Sources MWState m Blocks)
    -> Blocks -> ParsecT Sources MWState m Blocks
    forall a b. (a -> b) -> a -> b
    $ Attr -> Inlines -> Text -> Text -> Blocks
    B.simpleFigureWith
                     Attr
    attr ([Inline] -> Inlines
    forall a. [a] -> Many a
    B.fromList [Inline]
    figureCaption) Text
    src Text
    title
             [Inline]
    _ -> Blocks -> ParsecT Sources MWState m Blocks
    forall a. a -> ParsecT Sources MWState m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> ParsecT Sources MWState m Blocks)
    -> Blocks -> ParsecT Sources MWState m Blocks
    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
      MWParser m ()
    forall (m :: * -> *). PandocMonad m => MWParser m ()
    tableStart
      styles <- [Attribute Text]
    -> ParsecT Sources MWState m [Attribute Text]
    -> ParsecT Sources MWState m [Attribute Text]
    forall s (m :: * -> *) t a u.
    Stream s m t =>
    a -> ParsecT s u m a -> ParsecT s u m a
    option [] (ParsecT Sources MWState m [Attribute Text]
     -> ParsecT Sources MWState m [Attribute Text])
    -> ParsecT Sources MWState m [Attribute Text]
    -> ParsecT Sources MWState m [Attribute Text]
    forall a b. (a -> b) -> a -> b
    $
                   ParsecT Sources MWState m [Attribute Text]
    forall (m :: * -> *). PandocMonad m => MWParser m [Attribute Text]
    parseAttrs ParsecT Sources MWState m [Attribute Text]
    -> MWParser m () -> ParsecT Sources MWState m [Attribute Text]
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* ParsecT Sources MWState m Char -> MWParser m ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
    skipMany ParsecT Sources MWState m Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    spaceChar ParsecT Sources MWState m [Attribute Text]
    -> MWParser m () -> ParsecT Sources MWState m [Attribute Text]
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* ParsecT Sources MWState m Char -> MWParser m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional (Char -> ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '|')
      skipMany spaceChar
      optional $ template >> skipMany spaceChar
      optional blanklines
      let tableWidth = case Text -> [Attribute Text] -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup Text
    "width" [Attribute Text]
    styles of
                             Just Text
    w  -> Double -> Maybe Double -> Double
    forall a. a -> Maybe a -> a
    fromMaybe Double
    1.0 (Maybe Double -> Double) -> Maybe Double -> Double
    forall a b. (a -> b) -> a -> b
    $ Text -> Maybe Double
    parseWidth Text
    w
                             Maybe Text
    Nothing -> Double
    1.0
      caption <- option mempty tableCaption
      optional newline
      optional rowsep
      hasheader <- option False $ True <$ lookAhead (skipSpaces *> char '!')
      (cellwidths,hdr) <- unzip <$> tableRow
      let widths = (Double -> Double) -> [Double] -> [Double]
    forall a b. (a -> b) -> [a] -> [b]
    map (Double
    tableWidth Double -> Double -> Double
    forall a. Num a => a -> a -> a
    *) ([[Double]] -> [Double]
    forall (t :: * -> *) a. Foldable t => t [a] -> [a]
    concat [[Double]]
    cellwidths)
      let restwidth = Double
    tableWidth Double -> Double -> Double
    forall a. Num a => a -> a -> a
    - [Double] -> Double
    forall a. Num a => [a] -> a
    forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
    sum [Double]
    widths
      let zerocols = [Double] -> Int
    forall a. [a] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length ([Double] -> Int) -> [Double] -> Int
    forall a b. (a -> b) -> a -> b
    $ (Double -> Bool) -> [Double] -> [Double]
    forall a. (a -> Bool) -> [a] -> [a]
    filter (Double -> Double -> Bool
    forall a. Eq a => a -> a -> Bool
    ==Double
    0.0) [Double]
    widths
      let defaultwidth = if Int
    zerocols Int -> Int -> Bool
    forall a. Eq a => a -> a -> Bool
    == Int
    0 Bool -> Bool -> Bool
    || Int
    zerocols Int -> Int -> Bool
    forall a. Eq a => a -> a -> Bool
    == [Double] -> Int
    forall a. [a] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [Double]
    widths
                            then ColWidth
    ColWidthDefault
                            else Double -> ColWidth
    ColWidth (Double -> ColWidth) -> Double -> ColWidth
    forall a b. (a -> b) -> a -> b
    $ Double
    restwidth Double -> Double -> Double
    forall a. Fractional a => a -> a -> a
    / Int -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    zerocols
      let widths' = (Double -> ColWidth) -> [Double] -> [ColWidth]
    forall a b. (a -> b) -> [a] -> [b]
    map (\Double
    w -> if Double
    w Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    > Double
    0 then Double -> ColWidth
    ColWidth Double
    w else ColWidth
    defaultwidth) [Double]
    widths
      let cellspecs = [Alignment] -> [ColWidth] -> [(Alignment, ColWidth)]
    forall a b. [a] -> [b] -> [(a, b)]
    zip ([Cell] -> [Alignment]
    calculateAlignments [Cell]
    hdr) [ColWidth]
    widths'
      rows' <- many $ try $ rowsep *> (map snd <$> tableRow)
      optional blanklines
      tableEnd
      let (headers,rows) = if hasheader
                              then (hdr, rows')
                              else ([], hdr:rows')
      let toRow = Attr -> [Cell] -> Row
    Row Attr
    nullAttr
          toHeaderRow [Cell]
    l = [[Cell] -> Row
    toRow [Cell]
    l | Bool -> Bool
    not ([Cell] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [Cell]
    l)]
      return $ B.table (B.simpleCaption $ B.plain caption)
                       cellspecs
                       (TableHead nullAttr $ toHeaderRow headers)
                       [TableBody nullAttr 0 [] $ map toRow rows]
                       (TableFoot nullAttr [])

    calculateAlignments :: [Cell] -> [Alignment]
    calculateAlignments :: [Cell] -> [Alignment]
    calculateAlignments = (Cell -> [Alignment]) -> [Cell] -> [Alignment]
    forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
    concatMap Cell -> [Alignment]
    cellAligns
      where
        cellAligns :: Cell -> [Alignment]
        cellAligns :: Cell -> [Alignment]
    cellAligns (Cell Attr
    _ Alignment
    align RowSpan
    _ (ColSpan Int
    colspan) [Block]
    _) = Int -> Alignment -> [Alignment]
    forall a. Int -> a -> [a]
    replicate Int
    colspan Alignment
    align

    parseAttrs :: PandocMonad m => MWParser m [(Text,Text)]
    parseAttrs :: forall (m :: * -> *). PandocMonad m => MWParser m [Attribute Text]
    parseAttrs = ParsecT Sources MWState m (Attribute Text)
    -> ParsecT Sources MWState m [Attribute Text]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Sources MWState m (Attribute Text)
    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 = ParsecT Sources MWState m (Attribute Text)
    -> ParsecT Sources MWState m (Attribute Text)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m (Attribute Text)
     -> ParsecT Sources MWState m (Attribute Text))
    -> ParsecT Sources MWState m (Attribute Text)
    -> ParsecT Sources MWState m (Attribute Text)
    forall a b. (a -> b) -> a -> b
    $ do
      ParsecT Sources MWState m Char -> ParsecT Sources MWState m ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
    skipMany ParsecT Sources MWState m Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    spaceChar
      kFirst <- ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    letter
      kRest <- many (alphaNum <|> oneOf "_-:.")
      let k = [Char] -> Text
    T.pack (Char
    kFirst Char -> [Char] -> [Char]
    forall a. a -> [a] -> [a]
    : [Char]
    kRest)
      skipMany spaceChar
      char '='
      skipMany spaceChar
      v <- (char '"' >> manyTillChar (satisfy (/='\n')) (char '"'))
           <|> many1Char (satisfy $ \Char
    c -> Bool -> Bool
    not (Char -> Bool
    isSpace Char
    c) Bool -> Bool -> Bool
    && Char
    c Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    /= Char
    '|')
      return (k,v)

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

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

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

    cellsep :: PandocMonad m => MWParser m [(Text,Text)]
    cellsep :: forall (m :: * -> *). PandocMonad m => MWParser m [Attribute Text]
    cellsep = ParsecT Sources MWState m [Attribute Text]
    -> ParsecT Sources MWState m [Attribute Text]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m [Attribute Text]
     -> ParsecT Sources MWState m [Attribute Text])
    -> ParsecT Sources MWState m [Attribute Text]
    -> ParsecT Sources MWState m [Attribute Text]
    forall a b. (a -> b) -> a -> b
    $ do
      col <- SourcePos -> Int
    sourceColumn (SourcePos -> Int)
    -> ParsecT Sources MWState m SourcePos
    -> ParsecT Sources MWState m Int
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
      skipMany spaceChar
      c <- oneOf "|!"
      when (col > 1) $ void $ char c
      notFollowedBy (oneOf "-}")
      attribs <- option [] (parseAttrs <* skipMany spaceChar <* char '|')
      skipMany spaceChar
      pure attribs

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

    -- multiple widths because cell might have colspan
    tableCell :: PandocMonad m => MWParser m ([Double], Cell)
    tableCell :: forall (m :: * -> *). PandocMonad m => MWParser m ([Double], Cell)
    tableCell = ParsecT Sources MWState m ([Double], Cell)
    -> ParsecT Sources MWState m ([Double], Cell)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m ([Double], Cell)
     -> ParsecT Sources MWState m ([Double], Cell))
    -> ParsecT Sources MWState m ([Double], Cell)
    -> ParsecT Sources MWState m ([Double], Cell)
    forall a b. (a -> b) -> a -> b
    $ do
      attribs <- MWParser m [Attribute Text]
    forall (m :: * -> *). PandocMonad m => MWParser m [Attribute Text]
    cellsep
      pos' <- getPosition
      ls <- T.concat <$> many (notFollowedBy (void cellsep <|> rowsep <|> tableEnd) *>
                                ((snd <$> withRaw table) <|> countChar 1 anyChar))
      bs <- parseFromString (do setPosition pos'
                                mconcat <$> many block) ls
      let align = case Text -> [Attribute Text] -> Maybe Text
    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 rowspan = Int -> RowSpan
    RowSpan (Int -> RowSpan) -> (Maybe Int -> Int) -> Maybe Int -> RowSpan
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int -> Maybe Int -> Int
    forall a. a -> Maybe a -> a
    fromMaybe Int
    1 (Maybe Int -> RowSpan) -> Maybe Int -> RowSpan
    forall a b. (a -> b) -> a -> b
    $
                    Text -> Maybe Int
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead (Text -> Maybe Int) -> Maybe Text -> Maybe Int
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< Text -> [Attribute Text] -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup Text
    "rowspan" [Attribute Text]
    attribs
      let colspan = Int -> ColSpan
    ColSpan (Int -> ColSpan) -> (Maybe Int -> Int) -> Maybe Int -> ColSpan
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int -> Maybe Int -> Int
    forall a. a -> Maybe a -> a
    fromMaybe Int
    1 (Maybe Int -> ColSpan) -> Maybe Int -> ColSpan
    forall a b. (a -> b) -> a -> b
    $
                    Text -> Maybe Int
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead (Text -> Maybe Int) -> Maybe Text -> Maybe Int
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< Text -> [Attribute Text] -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup Text
    "colspan" [Attribute Text]
    attribs
      let ColSpan rawcolspan = colspan
      let handledAttribs = [Text
    "align", Text
    "colspan", Text
    "rowspan"]
          attribs' = [ (Text
    k, Text
    v) | (Text
    k, Text
    v) <- [Attribute Text]
    attribs
                              , Text
    k Text -> [Text] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `notElem` [Text]
    handledAttribs
                     ]
      let widths = case Text -> [Attribute Text] -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup Text
    "width" [Attribute Text]
    attribs of
                        Just Text
    xs -> [Double] -> (Double -> [Double]) -> Maybe Double -> [Double]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe (Int -> Double -> [Double]
    forall a. Int -> a -> [a]
    replicate Int
    rawcolspan Double
    0.0)
                                     (\Double
    w -> Int -> Double -> [Double]
    forall a. Int -> a -> [a]
    replicate Int
    rawcolspan
                                        (Double
    w Double -> Double -> Double
    forall a. Fractional a => a -> a -> a
    / Int -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    rawcolspan))
                                     (Text -> Maybe Double
    parseWidth Text
    xs)
                        Maybe Text
    Nothing -> Int -> Double -> [Double]
    forall a. Int -> a -> [a]
    replicate Int
    rawcolspan Double
    0.0
      return (widths, B.cellWith (toAttr attribs') align rowspan colspan 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 -> Text -> Maybe Double
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead (Text -> Maybe Double) -> Text -> Maybe Double
    forall a b. (a -> b) -> a -> b
    $ Text
    "0." Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    ds
        Maybe (Text, Char)
    _ -> Maybe Double
    forall a. Maybe a
    Nothing

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

    blockTag :: PandocMonad m => MWParser m Blocks
    blockTag :: forall (m :: * -> *). PandocMonad m => MWParser m Blocks
    blockTag = do
      (tag, _) <- ParsecT Sources MWState m (Tag Text, Text)
    -> ParsecT Sources MWState m (Tag Text, Text)
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead (ParsecT Sources MWState m (Tag Text, Text)
     -> ParsecT Sources MWState m (Tag Text, Text))
    -> ParsecT Sources MWState m (Tag Text, Text)
    -> ParsecT Sources MWState m (Tag Text, Text)
    forall a b. (a -> b) -> a -> b
    $ (Tag Text -> Bool) -> ParsecT Sources MWState m (Tag Text, Text)
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    (Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
    htmlTag Tag Text -> Bool
    isBlockTag'
      case tag of
          TagOpen Text
    "blockquote" [Attribute Text]
    _ -> Blocks -> Blocks
    B.blockQuote (Blocks -> Blocks)
    -> ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> ParsecT Sources MWState m Blocks
    forall (m :: * -> *). PandocMonad m => Text -> MWParser m Blocks
    blocksInTags Text
    "blockquote"
          TagOpen Text
    "pre" [Attribute Text]
    _ -> Text -> Blocks
    B.codeBlock (Text -> Blocks) -> (Text -> Text) -> Text -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text
    trimCode (Text -> Blocks)
    -> ParsecT Sources MWState m Text
    -> ParsecT Sources MWState m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> ParsecT Sources MWState m Text
    forall (m :: * -> *). PandocMonad m => Text -> MWParser m Text
    textInTags Text
    "pre"
          TagOpen Text
    "syntaxhighlight" [Attribute Text]
    attrs -> Text -> [Attribute Text] -> ParsecT Sources MWState m Blocks
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> [Attribute Text] -> MWParser m Blocks
    syntaxhighlight Text
    "syntaxhighlight" [Attribute Text]
    attrs
          TagOpen Text
    "source" [Attribute Text]
    attrs -> Text -> [Attribute Text] -> ParsecT Sources MWState m Blocks
    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"],[]) (Text -> Blocks) -> (Text -> Text) -> Text -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text
    trimCode (Text -> Blocks)
    -> ParsecT Sources MWState m Text
    -> ParsecT Sources MWState m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>
                                    Text -> ParsecT Sources MWState m Text
    forall (m :: * -> *). PandocMonad m => Text -> MWParser m Text
    textInTags Text
    "haskell"
          TagOpen Text
    "gallery" [Attribute Text]
    _ -> Text -> ParsecT Sources MWState m Blocks
    forall (m :: * -> *). PandocMonad m => Text -> MWParser m Blocks
    blocksInTags Text
    "gallery"
          TagOpen Text
    "p" [Attribute Text]
    _ -> Blocks
    forall a. Monoid a => a
    mempty Blocks
    -> ParsecT Sources MWState m (Tag Text, Text)
    -> ParsecT Sources MWState m Blocks
    forall a b.
    a -> ParsecT Sources MWState m b -> ParsecT Sources MWState m a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ (Tag Text -> Bool) -> ParsecT Sources MWState m (Tag Text, Text)
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    (Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
    htmlTag (Tag Text -> Tag Text -> Bool
    forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
    ~== Tag Text
    tag)
          TagClose Text
    "p"  -> Blocks
    forall a. Monoid a => a
    mempty Blocks
    -> ParsecT Sources MWState m (Tag Text, Text)
    -> ParsecT Sources MWState m Blocks
    forall a b.
    a -> ParsecT Sources MWState m b -> ParsecT Sources MWState m a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ (Tag Text -> Bool) -> ParsecT Sources MWState m (Tag Text, Text)
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    (Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
    htmlTag (Tag Text -> Tag Text -> Bool
    forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
    ~== Tag Text
    tag)
          Tag Text
    _ -> Text -> Text -> Blocks
    B.rawBlock Text
    "html" (Text -> Blocks)
    -> ((Tag Text, Text) -> Text) -> (Tag Text, Text) -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Tag Text, Text) -> Text
    forall a b. (a, b) -> b
    snd ((Tag Text, Text) -> Blocks)
    -> ParsecT Sources MWState m (Tag Text, Text)
    -> ParsecT Sources MWState m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (Tag Text -> Bool) -> ParsecT Sources MWState m (Tag Text, Text)
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    (Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
    htmlTag (Tag Text -> Tag Text -> Bool
    forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
    ~== 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 = ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m Blocks
     -> ParsecT Sources MWState m Blocks)
    -> ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      let mblang :: Maybe Text
    mblang = Text -> [Attribute Text] -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup Text
    "lang" [Attribute Text]
    attrs
      let mbstart :: Maybe Text
    mbstart = Text -> [Attribute Text] -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup Text
    "start" [Attribute Text]
    attrs
      let mbline :: Maybe Text
    mbline = Text -> [Attribute Text] -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup Text
    "line" [Attribute Text]
    attrs
      let classes :: [Text]
    classes = Maybe Text -> [Text]
    forall a. Maybe a -> [a]
    maybeToList Maybe Text
    mblang [Text] -> [Text] -> [Text]
    forall a. [a] -> [a] -> [a]
    ++ [Text] -> (Text -> [Text]) -> Maybe Text -> [Text]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [] ([Text] -> Text -> [Text]
    forall a b. a -> b -> a
    const [Text
    "numberLines"]) Maybe Text
    mbline
      let kvs :: [Attribute Text]
    kvs = [Attribute Text]
    -> (Text -> [Attribute Text]) -> Maybe Text -> [Attribute Text]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [] (\Text
    x -> [(Text
    "startFrom",Text
    x)]) Maybe Text
    mbstart
      contents <- Text -> MWParser m Text
    forall (m :: * -> *). PandocMonad m => Text -> MWParser m Text
    textInTags Text
    tag
      return $ B.codeBlockWith ("",classes,kvs) $ trimCode contents

    hrule :: PandocMonad m => MWParser m Blocks
    hrule :: forall (m :: * -> *). PandocMonad m => MWParser m Blocks
    hrule = Blocks
    B.horizontalRule Blocks
    -> ParsecT Sources MWState m Char
    -> ParsecT Sources MWState m Blocks
    forall a b.
    a -> ParsecT Sources MWState m b -> ParsecT Sources MWState m a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Sources MWState m Char -> ParsecT Sources MWState m Char
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ([Char] -> ParsecT Sources MWState m [Char]
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    "----" ParsecT Sources MWState m [Char]
    -> ParsecT Sources MWState m [Char]
    -> ParsecT Sources MWState m [Char]
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources MWState m Char -> ParsecT Sources MWState m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (Char -> ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '-') ParsecT Sources MWState m [Char]
    -> ParsecT Sources MWState m Char -> ParsecT Sources MWState m Char
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources MWState m Char
    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 = ParsecT Sources MWState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition ParsecT Sources MWState m SourcePos
    -> (SourcePos -> ParsecT Sources MWState m ())
    -> ParsecT Sources MWState m ()
    forall a b.
    ParsecT Sources MWState m a
    -> (a -> ParsecT Sources MWState m b)
    -> ParsecT Sources MWState m b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \SourcePos
    pos -> Bool -> ParsecT Sources MWState m ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (SourcePos -> Int
    sourceColumn SourcePos
    pos Int -> Int -> Bool
    forall a. Eq a => a -> a -> Bool
    == Int
    1)

    preformatted :: PandocMonad m => MWParser m Blocks
    preformatted :: forall (m :: * -> *). PandocMonad m => MWParser m Blocks
    preformatted = ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m Blocks
     -> ParsecT Sources MWState m Blocks)
    -> ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      MWParser m ()
    forall (m :: * -> *). PandocMonad m => MWParser m ()
    guardColumnOne
      Char -> ParsecT Sources MWState m Char
    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 Inlines -> ParsecT Sources u m Char -> ParsecT Sources u m Inlines
    forall a b. a -> ParsecT Sources u m b -> ParsecT Sources u m a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Sources u m Char -> ParsecT Sources u m Char
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources u m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    newline ParsecT Sources u m Char
    -> ParsecT Sources u m Char -> ParsecT Sources u m Char
    forall a b.
    ParsecT Sources u m a
    -> ParsecT Sources u m b -> ParsecT Sources u m a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* Char -> ParsecT Sources u m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    ' ')
      let whitespace' :: ParsecT Sources st m Inlines
    whitespace' = Text -> Inlines
    B.str (Text -> Inlines)
    -> ParsecT Sources st m Text -> ParsecT Sources st m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources st m Char -> ParsecT Sources st m Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParsecT s st m Char -> ParsecT s st m Text
    many1Char (Char
    '\160' Char -> ParsecT Sources st m Char -> ParsecT Sources st m Char
    forall a b. a -> ParsecT Sources st m b -> ParsecT Sources st m a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Sources st m Char
    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' = [Inlines] -> Inlines
    forall a. Monoid a => [a] -> a
    mconcat ([Inlines] -> Inlines) -> (Text -> [Inlines]) -> Text -> Inlines
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Inlines -> [Inlines] -> [Inlines]
    forall a. a -> [a] -> [a]
    intersperse Inlines
    B.linebreak ([Inlines] -> [Inlines])
    -> (Text -> [Inlines]) -> Text -> [Inlines]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text -> Inlines) -> [Text] -> [Inlines]
    forall a b. (a -> b) -> [a] -> [b]
    map Text -> Inlines
    B.str ([Text] -> [Inlines]) -> (Text -> [Text]) -> Text -> [Inlines]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                    Text -> [Text]
    T.lines (Text -> [Text]) -> (Text -> Text) -> Text -> [Text]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text
    fromEntities (Text -> Text) -> (Text -> Text) -> Text -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Char -> Char) -> Text -> Text
    T.map Char -> Char
    spToNbsp (Text -> Inlines)
    -> ParsecT Sources MWState m Text
    -> ParsecT Sources MWState m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m Text -> ParsecT Sources MWState m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try
                      ((Tag Text -> Bool) -> ParsecT Sources MWState m (Tag Text, Text)
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    (Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
    htmlTag (Tag Text -> Tag Text -> Bool
    forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
    ~== Text -> [Attribute Text] -> Tag Text
    forall str. str -> [Attribute str] -> Tag str
    TagOpen (Text
    "nowiki" :: Text) []) ParsecT Sources MWState m (Tag Text, Text)
    -> ParsecT Sources MWState m Text -> ParsecT Sources MWState m Text
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *>
                       ParsecT Sources MWState m Char
    -> ParsecT Sources MWState m (Tag Text, Text)
    -> ParsecT Sources MWState m Text
    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 ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    anyChar ((Tag Text -> Bool) -> ParsecT Sources MWState m (Tag Text, Text)
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    (Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
    htmlTag (Tag Text -> Tag Text -> Bool
    forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
    ~== Text -> Tag Text
    forall str. str -> Tag str
    TagClose (Text
    "nowiki" :: Text))))
      let inline' :: ParsecT Sources MWState m Inlines
    inline' = ParsecT Sources MWState m Inlines
    forall {st}. ParsecT Sources st m Inlines
    whitespace' ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    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
    forall {st}. ParsecT Sources st m Inlines
    endline' ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    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'
                      ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    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
    -> ParsecT Sources MWState m Inlines
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m Char -> MWParser m ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    newline MWParser m ()
    -> ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources MWState m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    inline)
      contents <- [Inlines] -> Inlines
    forall a. Monoid a => [a] -> a
    mconcat ([Inlines] -> Inlines)
    -> ParsecT Sources MWState m [Inlines]
    -> ParsecT Sources MWState m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m [Inlines]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Sources MWState m Inlines
    inline'
      let spacesStr (Str Text
    xs) = (Char -> Bool) -> Text -> Bool
    T.all Char -> Bool
    isSpace Text
    xs
          spacesStr Inline
    _        = Bool
    False
      if F.all spacesStr contents
         then return mempty
         else return $ B.para $ encode 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 = ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m Blocks
     -> ParsecT Sources MWState m Blocks)
    -> ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      MWParser m ()
    forall (m :: * -> *). PandocMonad m => MWParser m ()
    guardColumnOne
      lev <- [Char] -> Int
    forall a. [a] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length ([Char] -> Int)
    -> ParsecT Sources MWState m [Char]
    -> ParsecT Sources MWState m Int
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m Char -> ParsecT Sources MWState m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 (Char -> ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '=')
      guard $ lev <= 6
      contents <- trimInlines . mconcat <$> manyTill inline (count lev $ char '=')
      opts <- mwOptions <$> getState
      attr <- (if isEnabled Ext_gfm_auto_identifiers opts
                  then id
                  else modifyIdentifier) <$> registerHeader nullAttr contents
      return $ B.headerWith attr lev 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 Char -> Char -> Bool
    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 ([Blocks] -> Blocks)
    -> ParsecT Sources MWState m [Blocks]
    -> ParsecT Sources MWState m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>
       (   ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m [Blocks]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 (Char -> ParsecT Sources MWState m Blocks
    forall (m :: * -> *). PandocMonad m => Char -> MWParser m Blocks
    listItem Char
    '*')
       ParsecT Sources MWState m [Blocks]
    -> ParsecT Sources MWState m [Blocks]
    -> ParsecT Sources MWState m [Blocks]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ((Tag Text -> Bool) -> ParsecT Sources MWState m (Tag Text, Text)
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    (Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
    htmlTag (Tag Text -> Tag Text -> Bool
    forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
    ~== Text -> [Attribute Text] -> Tag Text
    forall str. str -> [Attribute str] -> Tag str
    TagOpen (Text
    "ul" :: Text) []) ParsecT Sources MWState m (Tag Text, Text)
    -> ParsecT Sources MWState m () -> ParsecT Sources MWState m ()
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources MWState m ()
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m ()
    spaces ParsecT Sources MWState m ()
    -> ParsecT Sources MWState m [Blocks]
    -> ParsecT Sources MWState m [Blocks]
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m [Blocks]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (Char -> ParsecT Sources MWState m Blocks
    forall (m :: * -> *). PandocMonad m => Char -> MWParser m Blocks
    listItem Char
    '*' ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m Blocks
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Sources MWState m Blocks
    forall (m :: * -> *). PandocMonad m => MWParser m Blocks
    li) ParsecT Sources MWState m [Blocks]
    -> ParsecT Sources MWState m ()
    -> ParsecT Sources MWState m [Blocks]
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <*
            ParsecT Sources MWState m (Tag Text, Text)
    -> ParsecT Sources MWState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional ((Tag Text -> Bool) -> ParsecT Sources MWState m (Tag Text, Text)
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    (Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
    htmlTag (Tag Text -> Tag Text -> Bool
    forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
    ~== Text -> Tag Text
    forall str. str -> Tag str
    TagClose (Text
    "ul" :: Text)))) )

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

    definitionList :: PandocMonad m => MWParser m Blocks
    definitionList :: forall (m :: * -> *). PandocMonad m => MWParser m Blocks
    definitionList = [(Inlines, [Blocks])] -> Blocks
    B.definitionList ([(Inlines, [Blocks])] -> Blocks)
    -> ParsecT Sources MWState m [(Inlines, [Blocks])]
    -> ParsecT Sources MWState m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m (Inlines, [Blocks])
    -> ParsecT Sources MWState m [(Inlines, [Blocks])]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Sources MWState m (Inlines, [Blocks])
    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 = ParsecT Sources MWState m (Inlines, [Blocks])
    -> ParsecT Sources MWState m (Inlines, [Blocks])
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m (Inlines, [Blocks])
     -> ParsecT Sources MWState m (Inlines, [Blocks]))
    -> ParsecT Sources MWState m (Inlines, [Blocks])
    -> ParsecT Sources MWState m (Inlines, [Blocks])
    forall a b. (a -> b) -> a -> b
    $ do
      terms <- [Inlines] -> Inlines
    forall a. Monoid a => [a] -> a
    mconcat ([Inlines] -> Inlines)
    -> ([Inlines] -> [Inlines]) -> [Inlines] -> Inlines
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Inlines -> [Inlines] -> [Inlines]
    forall a. a -> [a] -> [a]
    intersperse Inlines
    B.linebreak ([Inlines] -> Inlines)
    -> ParsecT Sources MWState m [Inlines]
    -> ParsecT Sources MWState m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m [Inlines]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many ParsecT Sources MWState m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    defListTerm
      -- we allow dd with no dt, or dt with no dd
      defs  <- if null terms
                  then notFollowedBy
                        (try $ skipMany1 (char ':') >> string "<math>") *>
                           many1 (listItem ':')
                  else many (listItem ':')
      return (terms, defs)

    defListTerm  :: PandocMonad m => MWParser m Inlines
    defListTerm :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    defListTerm = do
      MWParser m ()
    forall (m :: * -> *). PandocMonad m => MWParser m ()
    guardColumnOne
      Char -> ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    ';'
      ParsecT Sources MWState m Char -> MWParser m ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
    skipMany ParsecT Sources MWState m Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    spaceChar
      Inlines -> Inlines
    trimInlines (Inlines -> Inlines)
    -> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Inlines] -> Inlines
    forall a. Monoid a => [a] -> a
    mconcat ([Inlines] -> Inlines)
    -> ParsecT Sources MWState m [Inlines]
    -> ParsecT Sources MWState m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m [Inlines]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (ParsecT Sources MWState m Char -> MWParser m ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy ([Char] -> ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    oneOf [Char]
    ":\r\n") MWParser m ()
    -> ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources MWState m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    inline) ParsecT Sources MWState m Inlines
    -> MWParser m () -> ParsecT Sources MWState m Inlines
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <*
        ParsecT Sources MWState m Char -> MWParser m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    newline

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

    listStartChar :: PandocMonad m => MWParser m Char
    listStartChar :: forall (m :: * -> *). PandocMonad m => MWParser m Char
    listStartChar = [Char] -> ParsecT Sources MWState m Char
    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 = MWParser m ()
    forall (m :: * -> *). PandocMonad m => MWParser m ()
    guardColumnOne MWParser m ()
    -> ParsecT Sources MWState m Char -> ParsecT Sources MWState m Char
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> [Char] -> ParsecT Sources MWState m Char
    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 = ParsecT Sources MWState m (Tag Text, Text)
    -> ParsecT Sources MWState m (Tag Text, Text)
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead ((Tag Text -> Bool) -> ParsecT Sources MWState m (Tag Text, Text)
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    (Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
    htmlTag (Tag Text -> Tag Text -> Bool
    forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
    ~== Text -> [Attribute Text] -> Tag Text
    forall str. str -> [Attribute str] -> Tag str
    TagOpen (Text
    "li" :: Text) [])) ParsecT Sources MWState m (Tag Text, Text)
    -> ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m Blocks
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *>
         (Blocks -> Blocks
    firstParaToPlain (Blocks -> Blocks)
    -> ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> ParsecT Sources MWState m Blocks
    forall (m :: * -> *). PandocMonad m => Text -> MWParser m Blocks
    blocksInTags Text
    "li") ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m () -> ParsecT Sources MWState m Blocks
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* ParsecT Sources MWState m ()
    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 = ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m Blocks
     -> ParsecT Sources MWState m Blocks)
    -> ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      MWParser m ()
    forall (m :: * -> *). PandocMonad m => MWParser m ()
    guardColumnOne MWParser m () -> MWParser m () -> MWParser m ()
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Bool -> MWParser m ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Char
    c Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == Char
    ':') -- def can start on same line as term
      extras <- ParsecT Sources MWState m Char -> ParsecT Sources MWState m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (ParsecT Sources MWState m Char -> ParsecT Sources MWState m Char
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m Char -> ParsecT Sources MWState m Char)
    -> ParsecT Sources MWState m Char -> ParsecT Sources MWState m Char
    forall a b. (a -> b) -> a -> b
    $ Char -> ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    c ParsecT Sources MWState m Char
    -> ParsecT Sources MWState m Char -> ParsecT Sources MWState m Char
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* ParsecT Sources MWState m Char -> ParsecT Sources MWState m Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead ParsecT Sources MWState m Char
    forall (m :: * -> *). PandocMonad m => MWParser m Char
    listStartChar)
      if null extras
         then listItem' c
         else do
           skipMany spaceChar
           pos' <- getPosition
           first <- T.concat <$> manyTill listChunk newline
           rest <- many
                    (try $ string extras *> lookAhead listStartChar *>
                           (T.concat <$> manyTill listChunk newline))
           contents <- parseFromString (do setPosition pos'
                                           many1 $ listItem' c)
                              (T.unlines (first : rest))
           case c of
               Char
    '*' -> Blocks -> ParsecT Sources MWState m Blocks
    forall a. a -> ParsecT Sources MWState m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> ParsecT Sources MWState m Blocks)
    -> Blocks -> ParsecT Sources MWState m Blocks
    forall a b. (a -> b) -> a -> b
    $ [Blocks] -> Blocks
    B.bulletList [Blocks]
    contents
               Char
    '#' -> Blocks -> ParsecT Sources MWState m Blocks
    forall a. a -> ParsecT Sources MWState m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> ParsecT Sources MWState m Blocks)
    -> Blocks -> ParsecT Sources MWState m Blocks
    forall a b. (a -> b) -> a -> b
    $ [Blocks] -> Blocks
    B.orderedList [Blocks]
    contents
               Char
    ':' -> Blocks -> ParsecT Sources MWState m Blocks
    forall a. a -> ParsecT Sources MWState m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> ParsecT Sources MWState m Blocks)
    -> Blocks -> ParsecT Sources MWState m Blocks
    forall a b. (a -> b) -> a -> b
    $ [(Inlines, [Blocks])] -> Blocks
    B.definitionList [(Inlines
    forall a. Monoid a => a
    mempty, [Blocks]
    contents)]
               Char
    _   -> ParsecT Sources MWState m Blocks
    forall a. ParsecT Sources MWState m a
    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.
    -- Also multiline math: see #9293.
    listChunk :: PandocMonad m => MWParser m Text
    listChunk :: forall (m :: * -> *). PandocMonad m => MWParser m Text
    listChunk = MWParser m Text
    forall (m :: * -> *). PandocMonad m => MWParser m Text
    template MWParser m Text -> MWParser m Text -> MWParser m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ((Inlines, Text) -> Text
    forall a b. (a, b) -> b
    snd ((Inlines, Text) -> Text)
    -> ParsecT Sources MWState m (Inlines, Text) -> MWParser m Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m (Inlines, Text)
    forall (m :: * -> *) st a.
    Monad m =>
    ParsecT Sources st m a -> ParsecT Sources st m (a, Text)
    withRaw ParsecT Sources MWState m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    math) MWParser m Text -> MWParser m Text -> MWParser m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Int -> ParsecT Sources MWState m Char -> MWParser m Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char, Monad m) =>
    Int -> ParsecT s st m Char -> ParsecT s st m Text
    countChar Int
    1 ParsecT Sources MWState m Char
    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 = ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m Blocks
     -> ParsecT Sources MWState m Blocks)
    -> ParsecT Sources MWState m Blocks
    -> ParsecT Sources MWState m Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      Char -> MWParser m ()
    forall (m :: * -> *). PandocMonad m => Char -> MWParser m ()
    listStart Char
    c
      ParsecT Sources MWState m Char -> MWParser m ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
    skipMany ParsecT Sources MWState m Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    spaceChar
      pos' <- ParsecT Sources MWState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
      first <- T.concat <$> manyTill listChunk newline
      rest <- many (try $ char c *> lookAhead listStartChar *>
                       (T.concat <$> manyTill listChunk newline))
      parseFromString (do setPosition pos'
                          firstParaToPlain . mconcat <$> many1 block)
          $ T.unlines $ first : rest

    firstParaToPlain :: Blocks -> Blocks
    firstParaToPlain :: Blocks -> Blocks
    firstParaToPlain Blocks
    contents =
      case Seq Block -> ViewL Block
    forall a. Seq a -> ViewL a
    viewl (Blocks -> Seq Block
    forall a. Many a -> Seq a
    B.unMany Blocks
    contents) of
           Para [Inline]
    xs :< Seq Block
    ys -> Seq Block -> Blocks
    forall a. Seq a -> Many a
    B.Many (Seq Block -> Blocks) -> Seq Block -> Blocks
    forall a b. (a -> b) -> a -> b
    $ [Inline] -> Block
    Plain [Inline]
    xs Block -> Seq Block -> Seq Block
    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 =  MWParser m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    whitespace
          MWParser m Inlines -> MWParser m Inlines -> MWParser m Inlines
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> MWParser m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    url
          MWParser m Inlines -> MWParser m Inlines -> MWParser m Inlines
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> MWParser m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    str
          MWParser m Inlines -> MWParser m Inlines -> MWParser m Inlines
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> MWParser m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    doubleQuotes
          MWParser m Inlines -> MWParser m Inlines -> MWParser m Inlines
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> MWParser m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    strong
          MWParser m Inlines -> MWParser m Inlines -> MWParser m Inlines
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> MWParser m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    emph
          MWParser m Inlines -> MWParser m Inlines -> MWParser m Inlines
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> MWParser m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    image
          MWParser m Inlines -> MWParser m Inlines -> MWParser m Inlines
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> MWParser m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    internalLink
          MWParser m Inlines -> MWParser m Inlines -> MWParser m Inlines
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> MWParser m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    externalLink
          MWParser m Inlines -> MWParser m Inlines -> MWParser m Inlines
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> MWParser m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    math
          MWParser m Inlines -> MWParser m Inlines -> MWParser m Inlines
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> MWParser m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    inlineTag
          MWParser m Inlines -> MWParser m Inlines -> MWParser m Inlines
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Inline -> Inlines
    forall a. a -> Many a
    B.singleton (Inline -> Inlines)
    -> ParsecT Sources MWState m Inline -> MWParser m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m Inline
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Inline
    charRef
          MWParser m Inlines -> MWParser m Inlines -> MWParser m Inlines
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> MWParser m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    inlineHtml
          MWParser m Inlines -> MWParser m Inlines -> MWParser m Inlines
    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" (Text -> Inlines)
    -> ParsecT Sources MWState m Text -> MWParser m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m Text
    forall (m :: * -> *). PandocMonad m => MWParser m Text
    variable)
          MWParser m Inlines -> MWParser m Inlines -> MWParser m Inlines
    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" (Text -> Inlines)
    -> ParsecT Sources MWState m Text -> MWParser m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m Text
    forall (m :: * -> *). PandocMonad m => MWParser m Text
    template)
          MWParser m Inlines -> MWParser m Inlines -> MWParser m Inlines
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> MWParser m Inlines
    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 (Text -> Inlines)
    -> ParsecT Sources MWState m Text
    -> ParsecT Sources MWState m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m Char -> ParsecT Sources MWState m Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParsecT s st m Char -> ParsecT s st m Text
    many1Char ([Char] -> ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    noneOf ([Char] -> ParsecT Sources MWState m Char)
    -> [Char] -> ParsecT Sources MWState m Char
    forall a b. (a -> b) -> a -> b
    $ [Char]
    specialChars [Char] -> [Char] -> [Char]
    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 (Text -> Inlines) -> (Text -> Text) -> Text -> Inlines
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text
    trim (Text -> Inlines)
    -> ParsecT Sources MWState m Text
    -> ParsecT Sources MWState m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m Text -> ParsecT Sources MWState m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m Char -> ParsecT Sources MWState m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 (Char -> ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    ':') ParsecT Sources MWState m [Char]
    -> ParsecT Sources MWState m Text -> ParsecT Sources MWState m Text
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> Text -> ParsecT Sources MWState m Text
    forall (m :: * -> *). PandocMonad m => Text -> MWParser m Text
    textInTags Text
    "math"))
       ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> (Text -> Inlines
    B.math (Text -> Inlines) -> (Text -> Text) -> Text -> Inlines
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text
    trim (Text -> Inlines)
    -> ParsecT Sources MWState m Text
    -> ParsecT Sources MWState m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> ParsecT Sources MWState m Text
    forall (m :: * -> *). PandocMonad m => Text -> MWParser m Text
    textInTags Text
    "math")
       ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> (Text -> Inlines
    B.displayMath (Text -> Inlines) -> (Text -> Text) -> Text -> Inlines
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text
    trim (Text -> Inlines)
    -> ParsecT Sources MWState m Text
    -> ParsecT Sources MWState m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m Text -> ParsecT Sources MWState m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m [Char]
    forall {u}. ParsecT Sources u m [Char]
    dmStart ParsecT Sources MWState m [Char]
    -> ParsecT Sources MWState m Text -> ParsecT Sources MWState m Text
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources MWState m Char
    -> ParsecT Sources MWState m [Char]
    -> ParsecT Sources MWState m Text
    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 ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    anyChar ParsecT Sources MWState m [Char]
    forall {u}. ParsecT Sources u m [Char]
    dmEnd))
       ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> (Text -> Inlines
    B.math (Text -> Inlines) -> (Text -> Text) -> Text -> Inlines
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text
    trim (Text -> Inlines)
    -> ParsecT Sources MWState m Text
    -> ParsecT Sources MWState m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m Text -> ParsecT Sources MWState m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m [Char]
    forall {u}. ParsecT Sources u m [Char]
    mStart ParsecT Sources MWState m [Char]
    -> ParsecT Sources MWState m Text -> ParsecT Sources MWState m Text
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources MWState m Char
    -> ParsecT Sources MWState m [Char]
    -> ParsecT Sources MWState m Text
    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 ((Char -> Bool) -> ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    (Char -> Bool) -> ParsecT s u m Char
    satisfy (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    /=Char
    '\n')) ParsecT Sources MWState m [Char]
    forall {u}. ParsecT Sources u m [Char]
    mEnd))
     where dmStart :: ParsecT Sources u m [Char]
    dmStart = [Char] -> ParsecT Sources u m [Char]
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    "\\["
           dmEnd :: ParsecT Sources u m [Char]
    dmEnd   = ParsecT Sources u m [Char] -> ParsecT Sources u m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ([Char] -> ParsecT Sources u m [Char]
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    "\\]")
           mStart :: ParsecT Sources u m [Char]
    mStart  = [Char] -> ParsecT Sources u m [Char]
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    "\\("
           mEnd :: ParsecT Sources u m [Char]
    mEnd    = ParsecT Sources u m [Char] -> ParsecT Sources u m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ([Char] -> ParsecT Sources u m [Char]
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    "\\)")

    variable :: PandocMonad m => MWParser m Text
    variable :: forall (m :: * -> *). PandocMonad m => MWParser m Text
    variable = ParsecT Sources MWState m Text -> ParsecT Sources MWState m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m Text -> ParsecT Sources MWState m Text)
    -> ParsecT Sources MWState m Text -> ParsecT Sources MWState m Text
    forall a b. (a -> b) -> a -> b
    $ do
      [Char] -> ParsecT Sources MWState m [Char]
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    "{{{"
      contents <- ParsecT Sources MWState m Char
    -> ParsecT Sources MWState m [Char]
    -> ParsecT Sources MWState m Text
    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 ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    anyChar (ParsecT Sources MWState m [Char]
    -> ParsecT Sources MWState m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m [Char]
     -> ParsecT Sources MWState m [Char])
    -> ParsecT Sources MWState m [Char]
    -> ParsecT Sources MWState m [Char]
    forall a b. (a -> b) -> a -> b
    $ [Char] -> ParsecT Sources MWState m [Char]
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    "}}}")
      return $ "{{{" <> contents <> "}}}"

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

    special :: PandocMonad m => MWParser m Inlines
    special :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    special = Text -> Inlines
    B.str (Text -> Inlines)
    -> ParsecT Sources MWState m Text
    -> ParsecT Sources MWState m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Int
    -> ParsecT Sources MWState m Char -> ParsecT Sources MWState m Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char, Monad m) =>
    Int -> ParsecT s st m Char -> ParsecT s st m Text
    countChar Int
    1 (ParsecT Sources MWState m (Tag Text, Text)
    -> ParsecT Sources MWState m ()
    forall b s (m :: * -> *) a st.
    (Show b, Stream s m a) =>
    ParsecT s st m b -> ParsecT s st m ()
    notFollowedBy' ((Tag Text -> Bool) -> ParsecT Sources MWState m (Tag Text, Text)
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    (Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
    htmlTag Tag Text -> Bool
    isBlockTag') ParsecT Sources MWState m ()
    -> ParsecT Sources MWState m Char -> ParsecT Sources MWState m Char
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *>
                                      [Char] -> ParsecT Sources MWState m Char
    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" (Text -> Inlines)
    -> ((Tag Text, Text) -> Text) -> (Tag Text, Text) -> Inlines
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Tag Text, Text) -> Text
    forall a b. (a, b) -> b
    snd ((Tag Text, Text) -> Inlines)
    -> ParsecT Sources MWState m (Tag Text, Text)
    -> ParsecT Sources MWState m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (Tag Text -> Bool) -> ParsecT Sources MWState m (Tag Text, Text)
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    (Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
    htmlTag Tag Text -> Bool
    isInlineTag'

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

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

    imageIdentifier :: PandocMonad m => MWParser m ()
    imageIdentifier :: forall (m :: * -> *). PandocMonad m => MWParser m ()
    imageIdentifier = ParsecT Sources MWState m () -> ParsecT Sources MWState m ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m () -> ParsecT Sources MWState m ())
    -> ParsecT Sources MWState m () -> ParsecT Sources MWState m ()
    forall a b. (a -> b) -> a -> b
    $ do
      ident <- [Char] -> Text
    T.pack ([Char] -> Text)
    -> ParsecT Sources MWState m [Char]
    -> ParsecT Sources MWState m Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m Char
    -> ParsecT Sources MWState m Char
    -> ParsecT Sources MWState m [Char]
    forall end s (m :: * -> *) t st a.
    (Show end, Stream s m t) =>
    ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
    many1Till ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    letter (Char -> ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    ':')
      guard $ T.toLower ident `elem`
                ["file", "image", "archivo", "datei", "fichier", "bild"]

    image :: PandocMonad m => MWParser m Inlines
    image :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    image = ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m Inlines
     -> ParsecT Sources MWState m Inlines)
    -> ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    forall a b. (a -> b) -> a -> b
    $ do
      Text -> MWParser m ()
    forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
    sym Text
    "[["
      MWParser m ()
    forall (m :: * -> *). PandocMonad m => MWParser m ()
    imageIdentifier
      fname <- Text -> Text
    addUnderscores (Text -> Text)
    -> ParsecT Sources MWState m Text -> ParsecT Sources MWState m Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m Char -> ParsecT Sources MWState m Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParsecT s st m Char -> ParsecT s st m Text
    many1Char ([Char] -> ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    noneOf [Char]
    "|]")
      _ <- many imageOption
      dims <- try (char '|' *> sepBy (manyChar digit) (char 'x') <* string "px")
              <|> return []
      _ <- many imageOption
      let 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
    "", [], [Attribute Text]
    kvs)
      caption <-   (B.str fname <$ sym "]]")
               <|> try (char '|' *> (mconcat <$> manyTill inline (sym "]]")))
      return $ B.imageWith attr fname (stringify caption) caption

    imageOption :: PandocMonad m => MWParser m Text
    imageOption :: forall (m :: * -> *). PandocMonad m => MWParser m Text
    imageOption = ParsecT Sources MWState m Text -> ParsecT Sources MWState m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m Text -> ParsecT Sources MWState m Text)
    -> ParsecT Sources MWState m Text -> ParsecT Sources MWState m Text
    forall a b. (a -> b) -> a -> b
    $ Char -> ParsecT Sources MWState m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '|' ParsecT Sources MWState m Char
    -> ParsecT Sources MWState m Text -> ParsecT Sources MWState m Text
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources MWState m Text
    forall {u}. ParsecT Sources u m Text
    opt
      where
        opt :: ParsecT Sources u m Text
    opt = ParsecT Sources u m Text -> ParsecT Sources u m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ([Text] -> ParsecT Sources u m Text
    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" ])
          ParsecT Sources u m Text
    -> ParsecT Sources u m Text -> ParsecT Sources u m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Sources u m Text -> ParsecT Sources u m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (Text -> ParsecT Sources u m Text
    forall s (m :: * -> *) u.
    (Stream s m Char, UpdateSourcePos s Char) =>
    Text -> ParsecT s u m Text
    textStr Text
    "frame")
          ParsecT Sources u m Text
    -> ParsecT Sources u m Text -> ParsecT Sources u m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Sources u m Text -> ParsecT Sources u m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ([Text] -> ParsecT Sources u m Text
    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="] ParsecT Sources u m Text
    -> ParsecT Sources u m [Char] -> ParsecT Sources u m Text
    forall a b.
    ParsecT Sources u m a
    -> ParsecT Sources u m b -> ParsecT Sources u m a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* ParsecT Sources u m Char -> ParsecT Sources u m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many ([Char] -> ParsecT Sources u m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    noneOf [Char]
    "|]"))

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

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

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

    url :: PandocMonad m => MWParser m Inlines
    url :: forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    url = do
      (orig, src) <- ParsecT Sources MWState m (Attribute Text)
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m (Attribute Text)
    uri
      return $ B.link src "" (B.str 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 (Inlines -> Inlines)
    -> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Inlines] -> Inlines
    forall a. Monoid a => [a] -> a
    mconcat ([Inlines] -> Inlines)
    -> ParsecT Sources MWState m [Inlines]
    -> ParsecT Sources MWState m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m [Inlines]
    -> ParsecT Sources MWState m [Inlines]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (MWParser m a
    start MWParser m a
    -> ParsecT Sources MWState m [Inlines]
    -> ParsecT Sources MWState m [Inlines]
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParsecT Sources MWState m Inlines
    -> MWParser m b -> ParsecT Sources MWState m [Inlines]
    forall end s (m :: * -> *) t st a.
    (Show end, Stream s m t) =>
    ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
    many1Till ParsecT Sources MWState m Inlines
    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 (Inlines -> Inlines)
    -> ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> MWParser m () -> MWParser m () -> ParsecT Sources MWState m Inlines
    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 = Text -> MWParser m ()
    forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
    sym Text
    "''"
              end :: MWParser m ()
    end   = MWParser m () -> MWParser m ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (MWParser m () -> MWParser m ()) -> MWParser m () -> MWParser m ()
    forall a b. (a -> b) -> a -> b
    $ MWParser m () -> MWParser m ()
    forall b s (m :: * -> *) a st.
    (Show b, Stream s m a) =>
    ParsecT s st m b -> ParsecT s st m ()
    notFollowedBy' (() () -> ParsecT Sources MWState m Inlines -> MWParser m ()
    forall a b.
    a -> ParsecT Sources MWState m b -> ParsecT Sources MWState m a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Sources MWState m Inlines
    forall (m :: * -> *). PandocMonad m => MWParser m Inlines
    strong) MWParser m () -> MWParser m () -> MWParser m ()
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> Text -> MWParser m ()
    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 (Inlines -> Inlines)
    -> ParsecT Sources MWState m Inlines
    -> ParsecT Sources MWState m Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> MWParser m () -> MWParser m () -> ParsecT Sources MWState m Inlines
    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 = Text -> MWParser m ()
    forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
    sym Text
    "'''"
              end :: MWParser m ()
    end   = Text -> MWParser m ()
    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
      Extension -> ParsecT Sources MWState m ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasReaderOptions st) =>
    Extension -> ParsecT s st m ()
    guardEnabled Extension
    Ext_smart
      inTT <- MWState -> Bool
    mwInTT (MWState -> Bool)
    -> ParsecT Sources MWState m MWState
    -> ParsecT Sources MWState m Bool
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources MWState m MWState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      guard (not inTT)
      B.doubleQuoted <$> inlinesBetween openDoubleQuote closeDoubleQuote
        where openDoubleQuote :: MWParser m Char
    openDoubleQuote = Text -> ParsecT Sources MWState m ()
    forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
    sym Text
    "\"" ParsecT Sources MWState m () -> MWParser m Char -> MWParser m Char
    forall a b.
    ParsecT Sources MWState m a
    -> ParsecT Sources MWState m b -> ParsecT Sources MWState m b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> MWParser m Char -> MWParser m Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead MWParser m Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    nonspaceChar
              closeDoubleQuote :: ParsecT Sources MWState m ()
    closeDoubleQuote = ParsecT Sources MWState m () -> ParsecT Sources MWState m ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources MWState m () -> ParsecT Sources MWState m ())
    -> ParsecT Sources MWState m () -> ParsecT Sources MWState m ()
    forall a b. (a -> b) -> a -> b
    $ Text -> ParsecT Sources MWState m ()
    forall (m :: * -> *). PandocMonad m => Text -> MWParser m ()
    sym Text
    "\""