@@ -110,16 +110,27 @@ htmlComment :: MWParser ()
110110htmlComment = () <$ htmlTag isCommentTag
111111
112112inlinesInTags :: String -> MWParser Inlines
113−inlinesInTags tag = trimInlines . mconcat <$> try
114− (manyTill inline (htmlTag (~== TagClose tag)))
113+inlinesInTags tag = try $ do
114+ (_,raw) <- htmlTag (~== TagOpen tag [])
115+ if '/' `elem` raw -- self-closing tag
116+ then return mempty
117+ else trimInlines . mconcat <$>
118+ manyTill inline (htmlTag (~== TagClose tag))
115119
116120blocksInTags :: String -> MWParser Blocks
117−blocksInTags tag = mconcat <$> try
118− (manyTill block (htmlTag (~== TagClose tag)))
121+blocksInTags tag = try $ do
122+ (_,raw) <- htmlTag (~== TagOpen tag [])
123+ if '/' `elem` raw -- self-closing tag
124+ then return mempty
125+ else mconcat <$> manyTill block (htmlTag (~== TagClose tag))
119126
120127charsInTags :: String -> MWParser [Char]
121−charsInTags tag = innerText . parseTags <$> try
122− (manyTill anyChar (htmlTag (~== TagClose tag)))
128+charsInTags tag = try $ do
129+ (_,raw) <- htmlTag (~== TagOpen tag [])
130+ if '/' `elem` raw -- self-closing tag
131+ then return ""
132+ else innerText . parseTags <$>
133+ manyTill anyChar (htmlTag (~== TagClose tag))
123134
124135--
125136-- main parser
@@ -146,8 +157,6 @@ block = mempty <$ skipMany1 blankline
146157 <|> mempty <$ try (spaces *> htmlComment)
147158 <|> preformatted
148159 <|> blockTag
149− <|> pTag
150− <|> blockHtml
151160 <|> template
152161 <|> para
153162
@@ -164,16 +173,17 @@ template = B.rawBlock "mediawiki" <$> doublebrackets
164173
165174blockTag :: MWParser Blocks
166175blockTag = do
167− (TagOpen t attrs, raw) <- htmlTag (\x -> isBlockTag' x && isTagOpen x)
168− case t of
169− "blockquote" -> B.blockQuote <$> blocksInTags "blockquote"
170− "pre" -> B.codeBlock . trimCode <$> charsInTags "pre"
171− "syntaxhighlight" -> syntaxhighlight attrs
172− "haskell" -> B.codeBlockWith ("",["haskell"],[]) . trimCode <$>
173− charsInTags "haskell"
174− "gallery" -> blocksInTags "gallery"
175− "p" -> return mempty
176− _ -> return $ B.rawBlock "html" raw
176+ (tag, _) <- lookAhead $ htmlTag isBlockTag'
177+ case tag of
178+ TagOpen "blockquote" _ -> B.blockQuote <$> blocksInTags "blockquote"
179+ TagOpen "pre" _ -> B.codeBlock . trimCode <$> charsInTags "pre"
180+ TagOpen "syntaxhighlight" attrs -> syntaxhighlight attrs
181+ TagOpen "haskell" _ -> B.codeBlockWith ("",["haskell"],[]) . trimCode <$>
182+ charsInTags "haskell"
183+ TagOpen "gallery" _ -> blocksInTags "gallery"
184+ TagOpen "p" _ -> mempty <$ htmlTag (~== tag)
185+ TagClose "p" -> mempty <$ htmlTag (~== tag)
186+ _ -> B.rawBlock "html" . snd <$> htmlTag (~== tag)
177187
178188trimCode :: String -> String
179189trimCode ('\n':xs) = stripTrailingNewlines xs
@@ -189,13 +199,6 @@ syntaxhighlight attrs = try $ do
189199 contents <- charsInTags "syntaxhighlight"
190200 return $ B.codeBlockWith ("",classes,kvs) $ trimCode contents
191201
192−-- We can just skip pTags, as contents will be treated as paragraphs
193−pTag :: MWParser Blocks
194−pTag = mempty <$ (htmlTag (\t -> t ~== TagOpen "p" [] || t ~== TagClose "p"))
195−
196−blockHtml :: MWParser Blocks
197−blockHtml = (B.rawBlock "html" . snd <$> htmlTag isBlockTag)
198−
199202hrule :: MWParser Blocks
200203hrule = B.horizontalRule <$ try (string "----" *> many (char '-') *> newline)
201204
@@ -271,7 +274,7 @@ anyListStart = char '*'
271274 <|> char ';'
272275
273276li :: MWParser Blocks
274−li = htmlTag (~== TagOpen "li" []) *>
277+li = lookAhead (htmlTag (~== TagOpen "li" [])) *>
275278 (firstParaToPlain <$> blocksInTags "li") <* spaces
276279
277280listItem :: Char -> MWParser Blocks
@@ -317,6 +320,7 @@ inline = whitespace
317320 <|> str
318321 <|> strong
319322 <|> emph
323+ <|> internalLink
320324 <|> externalLink
321325 <|> inlineTag
322326 <|> B.singleton <$> charRef
@@ -336,21 +340,25 @@ variable = B.rawInline "mediawiki" <$> triplebrackets
336340
337341inlineTag :: MWParser Inlines
338342inlineTag = do
339− (TagOpen t _, raw) <- htmlTag (\x -> isInlineTag x && isTagOpen x)
340− case t of
341− "nowiki" -> B.text . fromEntities <$> try
342− (manyTill anyChar (htmlTag (~== TagClose "nowiki")))
343− "br" -> B.linebreak <$
344− (optional (htmlTag (~== TagClose "br")) *> optional blankline)
345− "strike" -> B.strikeout <$> inlinesInTags "strike"
346− "del" -> B.strikeout <$> inlinesInTags "del"
347− "sub" -> B.subscript <$> inlinesInTags "sub"
348− "sup" -> B.superscript <$> inlinesInTags "sup"
349− "math" -> B.math <$> charsInTags "math"
350− "code" -> B.code <$> charsInTags "code"
351− "tt" -> B.code <$> charsInTags "tt"
352− "hask" -> B.codeWith ("",["haskell"],[]) <$> charsInTags "hask"
353− _ -> return $ B.rawInline "html" raw
343+ (tag, _) <- lookAhead $ htmlTag isInlineTag
344+ case tag of
345+ TagOpen "nowiki" _ -> try $ do
346+ (_,raw) <- htmlTag (~== tag)
347+ if '/' `elem` raw
348+ then return mempty
349+ else B.text . fromEntities <$>
350+ manyTill anyChar (htmlTag (~== TagClose "nowiki"))
351+ TagOpen "br" _ -> B.linebreak <$ (htmlTag (~== TagOpen "br" []) -- will get /> too
352+ *> optional blankline)
353+ TagOpen "strike" _ -> B.strikeout <$> inlinesInTags "strike"
354+ TagOpen "del" _ -> B.strikeout <$> inlinesInTags "del"
355+ TagOpen "sub" _ -> B.subscript <$> inlinesInTags "sub"
356+ TagOpen "sup" _ -> B.superscript <$> inlinesInTags "sup"
357+ TagOpen "math" _ -> B.math <$> charsInTags "math"
358+ TagOpen "code" _ -> B.code <$> charsInTags "code"
359+ TagOpen "tt" _ -> B.code <$> charsInTags "tt"
360+ TagOpen "hask" _ -> B.codeWith ("",["haskell"],[]) <$> charsInTags "hask"
361+ _ -> B.rawInline "html" . snd <$> htmlTag (~== tag)
354362
355363special :: MWParser Inlines
356364special = B.str <$> count 1 (notFollowedBy' (htmlTag isBlockTag') *>
@@ -368,6 +376,19 @@ endline = () <$ try (newline <*
368376 notFollowedBy' hrule <*
369377 notFollowedBy anyListStart)
370378
379+internalLink :: MWParser Inlines
380+internalLink = try $ do
381+ string "[["
382+ pagename <- unwords . words <$> many (noneOf "|]")
383+ label <- option (B.text pagename) $ char '|' *>
384+ ( (mconcat <$> many1 (notFollowedBy (char ']') *> inline))
385+ -- the "pipe trick"
386+ -- [[Help:Contents|] -> "Contents"
387+ <|> (return $ B.text $ drop 1 $ dropWhile (/=':') pagename) )
388+ string "]]"
389+ linktrail <- B.text <$> many (char '\'' <|> letter)
390+ return $ B.link pagename "wikilink" (label <> linktrail)
391+
371392externalLink :: MWParser Inlines
372393externalLink = try $ do
373394 char '['