git.iko.soy/typeable/pandoc
on master help sign in
MediaWiki reader: Support `<syntaxhighlight>` tag.
commitbb6fcf1dac79943c84dacb4a27ee163911b03bff authorJohn MacFarlane <fiddlosopher@gmail.com> dateWed 12 Sep 2012, 19:05 (14 years ago) parentbf77889
1 file changed+13−3
src/Text/Pandoc/Readers/MediaWiki.hs+13−3
src/Text/Pandoc/Readers/MediaWiki.hs+13−3
@@ -36,9 +36,6 @@ _ support list style attributes and start values in ol lists, also
3636 value attribute on li
3737_ support preformatted text (lines starting with space)
3838_ support preformatted text blocks
39−_ code highlighting: http://www.mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi <syntaxhighlight lang="php"> (alternativel, <source...>)
40− if 'line' attribute present, number lines
41− if 'start' present, set starting line number
4239_ support internal links http://www.mediawiki.org/wiki/Help:Links
4340_ support external links
4441_ support automatic linkification of URLs
@@ -137,6 +134,7 @@ block = header
137134 <|> definitionList
138135 <|> blockquote
139136 <|> codeblock
137+ <|> syntaxhighlight
140138 <|> haskell
141139 <|> mempty <$ skipMany1 blankline
142140 <|> mempty <$ try (spaces *> htmlComment)
@@ -167,6 +165,18 @@ trimCode :: String -> String
167165trimCode ('\n':xs) = stripTrailingNewlines xs
168166trimCode xs = stripTrailingNewlines xs
169167
168+syntaxhighlight :: MWParser Blocks
169+syntaxhighlight = try $ do
170+ (tag@(TagOpen _ attrs), _) <- lookAhead
171+ $ htmlTag (~== TagOpen "syntaxhighlight" [])
172+ let mblang = lookup "lang" attrs
173+ let mbstart = lookup "start" attrs
174+ let mbline = lookup "line" attrs
175+ let classes = maybe [] (:[]) mblang ++ maybe [] (const ["numberLines"]) mbline
176+ let kvs = maybe [] (\x -> [("startFrom",x)]) mbstart
177+ contents <- charsInTags "syntaxhighlight"
178+ return $ B.codeBlockWith ("",classes,kvs) contents
179+
170180haskell :: MWParser Blocks
171181haskell = B.codeBlockWith ("",["haskell"],[]) . trimCode <$>
172182 charsInTags "haskell"