module Text.Pandoc.Highlighting ( languages
, languagesByExtension
, highlight
, formatLaTeXInline
, formatLaTeXBlock
, styleToLaTeX
, formatHtmlInline
, formatHtmlBlock
, styleToCss
, pygments
, espresso
, zenburn
, tango
, kate
, monochrome
, haddock
, Style
) where
import Text.Pandoc.Definition
import Text.Pandoc.Shared (safeRead)
import Text.Highlighting.Kate
import Data.List (find)
import Data.Maybe (fromMaybe)
import Data.Char (toLower)
lcLanguages :: [String]
lcLanguages = map (map toLower) languages
highlight :: (FormatOptions -> [SourceLine] -> a)
-> Attr
-> String
-> Maybe a
highlight formatter (_, classes, keyvals) rawCode =
let firstNum = case safeRead (fromMaybe "1" $ lookup "startFrom" keyvals) of
Just n -> n
Nothing -> 1
fmtOpts = defaultFormatOpts{
startNumber = firstNum,
numberLines = any (`elem`
["number","numberLines", "number-lines"]) classes }
lcclasses = map (map toLower) classes
in case find (`elem` lcLanguages) lcclasses of
Nothing -> Nothing
Just language -> Just
$ formatter fmtOpts{ codeClasses = [language],
containerClasses = classes }
$ highlightAs language rawCode