@@ -36,10 +36,11 @@ import Text.Pandoc.Readers.TeXMath
3636import Text.Regex ( mkRegex, matchRegex )
3737import Numeric ( showHex )
3838import Data.Char ( ord, toLower, isAlpha )
39−import Data.List ( isPrefixOf, intersperse )
39+import Data.List ( isPrefixOf, intersperse, find )
4040import qualified Data.Set as S
4141import Control.Monad.State
4242import Text.XHtml.Transitional
43+import Text.Highlighting.Kate
4344
4445data WriterState = WriterState
4546 { stNotes :: [Html] -- ^ List of notes
@@ -263,9 +264,18 @@ blockToHtml opts (Plain lst) = inlineListToHtml opts lst
263264blockToHtml opts (Para lst) = inlineListToHtml opts lst >>= (return . paragraph)
264265blockToHtml opts (RawHtml str) = return $ primHtml str
265266blockToHtml opts (HorizontalRule) = return $ hr
266−blockToHtml opts (CodeBlock (_,classes,_) str) = return $
267− pre ! (if null classes then [] else [theclass $ unwords classes]) $
268− thecode << (str ++ "\n") -- the final \n for consistency with Markdown.pl
267+blockToHtml opts (CodeBlock (_,classes,_) rawCode) = do
268+ let fmtOpts =
269+ case find (`elem` ["number","numberLines","number-lines"]) classes of
270+ Nothing -> []
271+ Just _ -> [OptNumberLines]
272+ let toPre str = pre ! (if null classes then [] else [theclass $ unwords classes]) $ thecode << str
273+ let lcLanguages = map (map toLower) languages
274+ return $ case find (\c -> (map toLower c) `elem` lcLanguages) classes of
275+ Nothing -> toPre (rawCode ++ "\n")
276+ Just lang -> case highlightAs lang rawCode of
277+ Left _ -> toPre (rawCode ++ "\n")
278+ Right hl -> formatAsXHtml fmtOpts lang hl
269279blockToHtml opts (BlockQuote blocks) =
270280 -- in S5, treat list in blockquote specially
271281 -- if default is incremental, make it nonincremental;