git.iko.soy/typeable/pandoc
on master help sign in
Add default CSS to document header if syntax highlighting used.
c150e84fiddlosopher
Text/Pandoc/Writers/HTML.hs+27−5
@@ -216,6 +216,27 @@ addToCSS item = do
216 let current = stCSS st
216 let current = stCSS st
217 put $ st {stCSS = S.insert item current}
217 put $ st {stCSS = S.insert item current}
218
218
219+-- | Generic CSS for syntax highlighting.
220+highlightingCSS :: String
221+highlightingCSS =
222+ "pre.sourceCode { }\n\
223+ \pre.sourceCode span.LineNumber { display: none; }\n\
224+ \pre.numberLines span.LineNumber { display: inline; color: #AAAAAA; padding-right: 0; border-right: 1px solid #AAAAAA; margin-right: 3px; }\n\
225+ \pre.sourceCode span.Normal { }\n\
226+ \pre.sourceCode span.Keyword { color: #007020; font-weight: bold; } \n\
227+ \pre.sourceCode span.DataType { color: #902000; }\n\
228+ \pre.sourceCode span.DecVal { color: #40a070; }\n\
229+ \pre.sourceCode span.BaseN { color: #40a070; }\n\
230+ \pre.sourceCode span.Float { color: #40a070; }\n\
231+ \pre.sourceCode span.Char { color: #4070a0; }\n\
232+ \pre.sourceCode span.String { color: #4070a0; }\n\
233+ \pre.sourceCode span.Comment { color: #60a0b0; font-style: italic; }\n\
234+ \pre.sourceCode span.Others { color: #007020; }\n\
235+ \pre.sourceCode span.Alert { color: red; font-weight: bold; }\n\
236+ \pre.sourceCode span.Function { color: #06287e; }\n\
237+ \pre.sourceCode span.RegionMarker { }\n\
238+ \pre.sourceCode span.Error { color: red; font-weight: bold; }"
239+
219-- | Convert Pandoc inline list to plain text identifier.
240-- | Convert Pandoc inline list to plain text identifier.
220inlineListToIdentifier :: [Inline] -> String
241inlineListToIdentifier :: [Inline] -> String
221inlineListToIdentifier = dropWhile (not . isAlpha) . inlineListToIdentifier'
242inlineListToIdentifier = dropWhile (not . isAlpha) . inlineListToIdentifier'
@@ -271,11 +292,12 @@ blockToHtml opts (CodeBlock (_,classes,_) rawCode) = do
271 Just _ -> [OptNumberLines]
292 Just _ -> [OptNumberLines]
272 let toPre str = pre ! (if null classes then [] else [theclass $ unwords classes]) $ thecode << str
293 let toPre str = pre ! (if null classes then [] else [theclass $ unwords classes]) $ thecode << str
273 let lcLanguages = map (map toLower) languages
294 let lcLanguages = map (map toLower) languages
274− return $ case find (\c -> (map toLower c) `elem` lcLanguages) classes of
295+ case find (\c -> (map toLower c) `elem` lcLanguages) classes of
275− Nothing -> toPre (rawCode ++ "\n")
296+ Nothing -> return $ toPre (rawCode ++ "\n")
276− Just lang -> case highlightAs lang rawCode of
297+ Just lang -> case highlightAs lang rawCode of
277− Left _ -> toPre (rawCode ++ "\n")
298+ Left _ -> return $ toPre (rawCode ++ "\n")
299+ Right hl -> do addToCSS highlightingCSS
278− Right hl -> formatAsXHtml fmtOpts lang hl
300+ return $ formatAsXHtml fmtOpts lang hl
279blockToHtml opts (BlockQuote blocks) =
301blockToHtml opts (BlockQuote blocks) =
280 -- in S5, treat list in blockquote specially
302 -- in S5, treat list in blockquote specially
281 -- if default is incremental, make it nonincremental;
303 -- if default is incremental, make it nonincremental;