@@ -29,57 +29,41 @@ Exports functions for syntax highlighting.
2929-}
3030
3131module Text.Pandoc.Highlighting ( languages
32− , highlightHtml
33− , highlightLaTeX
34− , defaultHighlightingCss
35− , defaultLaTeXMacros
3632 , languagesByExtension
33+ , highlight
34+ , formatLaTeXInline
35+ , formatLaTeXBlock
36+ , styleToLaTeX
37+ , formatHtmlInline
38+ , formatHtmlBlock
39+ , styleToHtml
40+ , pygments
3741 ) where
38−import Text.Blaze
3942import Text.Pandoc.Definition
40−import Text.Highlighting.Kate ( SourceLine, languages, highlightAs, formatAsHtml,
41− TokenType(..), formatAsLaTeX, FormatOption (..), defaultHighlightingCss,
42− defaultLaTeXMacros, languagesByExtension )
43+import Text.Highlighting.Kate
4344import Data.List (find)
4445import Data.Maybe (fromMaybe)
4546import Data.Char (toLower)
46−import qualified Text.Blaze.Html5.Attributes as A
4747
48−highlight :: ([FormatOption] -> String -> [SourceLine] -> a) -- ^ Formatter
49− -> Bool -- ^ True if inline
50− -> Attr -- ^ Attributes of the Code or CodeBlock
51− -> String -- ^ Raw contents of the Code or CodeBlock
52− -> Maybe a -- ^ Maybe the formatted result
53−highlight formatter inline (_, classes, keyvals) rawCode =
48+lcLanguages :: [String]
49+lcLanguages = map (map toLower) languages
50+
51+highlight :: (FormatOptions -> [SourceLine] -> a) -- ^ Formatter
52+ -> Attr -- ^ Attributes of the CodeBlock
53+ -> String -- ^ Raw contents of the CodeBlock
54+ -> Maybe a -- ^ Maybe the formatted result
55+highlight formatter (_, classes, keyvals) rawCode =
5456 let firstNum = case reads (fromMaybe "1" $ lookup "startFrom" keyvals) of
5557 ((n,_):_) -> n
5658 [] -> 1
57− fmtOpts = [OptNumberFrom firstNum] ++
58− [OptInline | inline] ++
59− case find (`elem` ["number","numberLines","number-lines"]) classes of
60− Nothing -> []
61− Just _ -> [OptNumberLines]
62− addBirdTracks = "literate" `elem` classes
63− lcLanguages = map (map toLower) languages
64− in case find (\c -> (map toLower c) `elem` lcLanguages) classes of
59+ fmtOpts = defaultFormatOpts{
60+ startNumber = firstNum,
61+ numberLines = any (`elem`
62+ ["number","numberLines", "number-lines"]) classes }
63+ lcclasses = map (map toLower) classes
64+ in case find (`elem` lcLanguages) lcclasses of
6565 Nothing -> Nothing
6666 Just language -> Just
67− $ formatter fmtOpts language .
68− (if addBirdTracks
69− then map ((OtherTok,"> "):)
70− else id)
67+ $ formatter fmtOpts
7168 $ highlightAs language rawCode
7269
73−highlightHtml :: Bool -- ^ True if inline HTML
74− -> Attr -- ^ Attributes of the Code or CodeBlock
75− -> String -- ^ Raw contents of the Code or CodeBlock
76− -> Maybe Html -- ^ Maybe formatted Html
77−highlightHtml inline attr@(id',_,_) = fmap addId . highlight formatAsHtml inline attr
78− where addId = if null id' then id else (! A.id (toValue id'))
79−
80−highlightLaTeX :: Bool -- ^ True if inline
81− -> Attr -- ^ Attributes of the Code or CodeBlock
82− -> String -- ^ Raw contents of the Code or CodeBlock
83− -> Maybe String -- ^ Maybe formatted LaTeX
84−highlightLaTeX = highlight formatAsLaTeX
85−