git.iko.soy/typeable/pandoc
on master help sign in
MediaWiki reader: Support `<syntaxhighlight>` tag.
bb6fcf1John MacFarlane
src/Text/Pandoc/Readers/MediaWiki.hs+13−3
@@ -36,9 +36,6 @@ _ support list style attributes and start values in ol lists, also
36 value attribute on li
36 value attribute on li
37_ support preformatted text (lines starting with space)
37_ support preformatted text (lines starting with space)
38_ support preformatted text blocks
38_ 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
42_ support internal links http://www.mediawiki.org/wiki/Help:Links
39_ support internal links http://www.mediawiki.org/wiki/Help:Links
43_ support external links
40_ support external links
44_ support automatic linkification of URLs
41_ support automatic linkification of URLs
@@ -137,6 +134,7 @@ block = header
137 <|> definitionList
134 <|> definitionList
138 <|> blockquote
135 <|> blockquote
139 <|> codeblock
136 <|> codeblock
137+ <|> syntaxhighlight
140 <|> haskell
138 <|> haskell
141 <|> mempty <$ skipMany1 blankline
139 <|> mempty <$ skipMany1 blankline
142 <|> mempty <$ try (spaces *> htmlComment)
140 <|> mempty <$ try (spaces *> htmlComment)
@@ -167,6 +165,18 @@ trimCode :: String -> String
167trimCode ('\n':xs) = stripTrailingNewlines xs
165trimCode ('\n':xs) = stripTrailingNewlines xs
168trimCode xs = stripTrailingNewlines xs
166trimCode xs = stripTrailingNewlines xs
169
167
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+
170haskell :: MWParser Blocks
180haskell :: MWParser Blocks
171haskell = B.codeBlockWith ("",["haskell"],[]) . trimCode <$>
181haskell = B.codeBlockWith ("",["haskell"],[]) . trimCode <$>
172 charsInTags "haskell"
182 charsInTags "haskell"