aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-09-12 19:05:15 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2012-09-12 19:05:15 -0700
commitbb6fcf1dac79943c84dacb4a27ee163911b03bff (patch)
tree492c1a8c4ff5c5a60df96867c4a73dd645efab1c
parentbf77889e195121cec03490fc22f68975574abcad (diff)
downloadpandoc-bb6fcf1dac79943c84dacb4a27ee163911b03bff.tar.gz
MediaWiki reader: Support `<syntaxhighlight>` tag.
-rw-r--r--src/Text/Pandoc/Readers/MediaWiki.hs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs
index 7a22d21d4..97747ecee 100644
--- a/src/Text/Pandoc/Readers/MediaWiki.hs
+++ b/src/Text/Pandoc/Readers/MediaWiki.hs
@@ -36,9 +36,6 @@ _ support list style attributes and start values in ol lists, also
value attribute on li
_ support preformatted text (lines starting with space)
_ support preformatted text blocks
-_ code highlighting: http://www.mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi <syntaxhighlight lang="php"> (alternativel, <source...>)
- if 'line' attribute present, number lines
- if 'start' present, set starting line number
_ support internal links http://www.mediawiki.org/wiki/Help:Links
_ support external links
_ support automatic linkification of URLs
@@ -137,6 +134,7 @@ block = header
<|> definitionList
<|> blockquote
<|> codeblock
+ <|> syntaxhighlight
<|> haskell
<|> mempty <$ skipMany1 blankline
<|> mempty <$ try (spaces *> htmlComment)
@@ -167,6 +165,18 @@ trimCode :: String -> String
trimCode ('\n':xs) = stripTrailingNewlines xs
trimCode xs = stripTrailingNewlines xs
+syntaxhighlight :: MWParser Blocks
+syntaxhighlight = try $ do
+ (tag@(TagOpen _ attrs), _) <- lookAhead
+ $ htmlTag (~== TagOpen "syntaxhighlight" [])
+ let mblang = lookup "lang" attrs
+ let mbstart = lookup "start" attrs
+ let mbline = lookup "line" attrs
+ let classes = maybe [] (:[]) mblang ++ maybe [] (const ["numberLines"]) mbline
+ let kvs = maybe [] (\x -> [("startFrom",x)]) mbstart
+ contents <- charsInTags "syntaxhighlight"
+ return $ B.codeBlockWith ("",classes,kvs) contents
+
haskell :: MWParser Blocks
haskell = B.codeBlockWith ("",["haskell"],[]) . trimCode <$>
charsInTags "haskell"