From c150e84d3c74555d7024c9b0c23a76ef13e73335 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Sat, 9 Feb 2008 03:20:25 +0000 Subject: Add default CSS to document header if syntax highlighting used. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1215 788f1e2b-df1e-0410-8736-df70ead52e1b --- Text/Pandoc/Writers/HTML.hs | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'Text/Pandoc') diff --git a/Text/Pandoc/Writers/HTML.hs b/Text/Pandoc/Writers/HTML.hs index df9a682a5..acb9f32bb 100644 --- a/Text/Pandoc/Writers/HTML.hs +++ b/Text/Pandoc/Writers/HTML.hs @@ -216,6 +216,27 @@ addToCSS item = do let current = stCSS st put $ st {stCSS = S.insert item current} +-- | Generic CSS for syntax highlighting. +highlightingCSS :: String +highlightingCSS = + "pre.sourceCode { }\n\ + \pre.sourceCode span.LineNumber { display: none; }\n\ + \pre.numberLines span.LineNumber { display: inline; color: #AAAAAA; padding-right: 0; border-right: 1px solid #AAAAAA; margin-right: 3px; }\n\ + \pre.sourceCode span.Normal { }\n\ + \pre.sourceCode span.Keyword { color: #007020; font-weight: bold; } \n\ + \pre.sourceCode span.DataType { color: #902000; }\n\ + \pre.sourceCode span.DecVal { color: #40a070; }\n\ + \pre.sourceCode span.BaseN { color: #40a070; }\n\ + \pre.sourceCode span.Float { color: #40a070; }\n\ + \pre.sourceCode span.Char { color: #4070a0; }\n\ + \pre.sourceCode span.String { color: #4070a0; }\n\ + \pre.sourceCode span.Comment { color: #60a0b0; font-style: italic; }\n\ + \pre.sourceCode span.Others { color: #007020; }\n\ + \pre.sourceCode span.Alert { color: red; font-weight: bold; }\n\ + \pre.sourceCode span.Function { color: #06287e; }\n\ + \pre.sourceCode span.RegionMarker { }\n\ + \pre.sourceCode span.Error { color: red; font-weight: bold; }" + -- | Convert Pandoc inline list to plain text identifier. inlineListToIdentifier :: [Inline] -> String inlineListToIdentifier = dropWhile (not . isAlpha) . inlineListToIdentifier' @@ -271,11 +292,12 @@ blockToHtml opts (CodeBlock (_,classes,_) rawCode) = do Just _ -> [OptNumberLines] let toPre str = pre ! (if null classes then [] else [theclass $ unwords classes]) $ thecode << str let lcLanguages = map (map toLower) languages - return $ case find (\c -> (map toLower c) `elem` lcLanguages) classes of - Nothing -> toPre (rawCode ++ "\n") - Just lang -> case highlightAs lang rawCode of - Left _ -> toPre (rawCode ++ "\n") - Right hl -> formatAsXHtml fmtOpts lang hl + case find (\c -> (map toLower c) `elem` lcLanguages) classes of + Nothing -> return $ toPre (rawCode ++ "\n") + Just lang -> case highlightAs lang rawCode of + Left _ -> return $ toPre (rawCode ++ "\n") + Right hl -> do addToCSS highlightingCSS + return $ formatAsXHtml fmtOpts lang hl blockToHtml opts (BlockQuote blocks) = -- in S5, treat list in blockquote specially -- if default is incremental, make it nonincremental; -- cgit v1.2.3