-- | Formats Haskell source code as HTML with inline CSS. module Language.Haskell.HsColour.InlineCSS (hscolour,top'n'tail) where import Language.Haskell.HsColour.Anchors import Language.Haskell.HsColour.Classify as Classify import Language.Haskell.HsColour.Colourise import Language.Haskell.HsColour.HTML (renderAnchors, renderComment, renderNewLinesAnchors, escape) import Text.Printf -- | Formats Haskell source code as a complete HTML document with inline styling hscolour :: ColourPrefs -- ^ Preferences for styling. -> Bool -- ^ Whether to include anchors. -> String -- ^ Haskell source code. -> String -- ^ An HTML document containing the coloured -- Haskell source code. hscolour prefs anchor = pre . (if anchor then renderNewLinesAnchors . concatMap (renderAnchors (renderToken prefs)) . insertAnchors else concatMap (renderToken prefs)) . tokenise top'n'tail :: String -> String -> String top'n'tail title = (cssPrefix title ++) . (++cssSuffix) pre :: String -> String pre = ("
"++) . (++"") renderToken :: ColourPrefs -> (TokenType,String) -> String renderToken prefs (cls,text) = stylise (colourise prefs cls) $ if cls == Comment then renderComment text else escape text stylise :: [Highlight] -> String -> String stylise hs s = "" ++s++ "" cssPrefix title = unlines ["" ,"" ,"" ,"" ,"" ,"