Permalink
Browse files

Format.HTML now exports styleToCss rather than styleToHtml.

This gives users more flexibility.
  • Loading branch information...
1 parent 68883f5 commit fe233d404a0eb1351ca57776051ad0ae5e899e57 John MacFarlane committed Jan 25, 2012
Showing with 5 additions and 8 deletions.
  1. +1 −1 Highlight.hs
  2. +4 −7 Text/Highlighting/Kate/Format/HTML.hs
View
@@ -129,7 +129,7 @@ hlHtml frag fname opts sty lang code =
then putStrLn $ renderHtml fragment
else putStrLn $ renderHtml $ H.head (pageTitle >> metadata >> css) >> H.body (toHtml fragment)
where fragment = formatHtmlBlock opts $ highlightAs lang code
- css = styleToHtml sty
+ css = H.style ! A.type_ "text/css" $ toHtml $ styleToCss sty
pageTitle = H.title $ toHtml fname
metadata = H.meta ! A.httpEquiv "Content-Type" ! A.content "text/html; charset=UTF-8" >>
H.meta ! A.name "generator" ! A.content "highlight-kate"
@@ -11,7 +11,7 @@ Formatters that convert a list of annotated source lines to HTML.
-}
module Text.Highlighting.Kate.Format.HTML (
- formatHtmlInline, formatHtmlBlock, styleToHtml
+ formatHtmlInline, formatHtmlBlock, styleToCss
) where
import Text.Highlighting.Kate.Types
import Text.Blaze
@@ -88,11 +88,9 @@ formatHtmlBlock opts ls = container ! A.class_ (toValue $ unwords classes)
>> toHtml "\n"
else toHtml $ show n ++ "\n"
--- | Returns an HTML @style@ block with definitions for
--- formatting highlighted code according to the given style.
-styleToHtml :: Style -> Html
-styleToHtml f = H.style ! A.type_ (toValue "text/css") $ toHtml
- $ unlines $ tablespec ++ colorspec ++ map toCss (tokenStyles f)
+-- | Returns CSS for styling highlighted code according to the given style.
+styleToCss :: Style -> String
+styleToCss f = unlines $ tablespec ++ colorspec ++ map toCss (tokenStyles f)
where colorspec = case (defaultColor f, backgroundColor f) of
(Nothing, Nothing) -> []
(Just c, Nothing) -> ["pre, code { color: " ++ fromColor c ++ "; }"]
@@ -124,4 +122,3 @@ toCss (t,tf) = "code > span." ++ short t ++ " { "
stylespec = if tokenItalic tf then "font-style: italic; " else ""
decorationspec = if tokenUnderline tf then "text-decoration: underline; " else ""
-

0 comments on commit fe233d4

Please sign in to comment.