views:

226

answers:

3

If I run a python source file through pygments, it outputs html code whose elements class belong to some CSS file pygments is using. Could the style attributes be included in the outputted html so that I don't have to provide a CSS file?

A: 

Usually, your code is only one of many things on a web page. You often want code to look different from the other content. You, generally, want to control the style of the code as part of the overall page style. CSS is your first, best choice for this.

However, you can embed the styles in the HTML if that seems better. Here's an example that shows the <style> tag in the <head> tag.

http://www.w3schools.com/TAGS/tag_style.asp

S.Lott
Scott, I want to do this programatically.
Geo
What does "programmatically" mean in this context? You get a document that references styles that you can provide. What else do you want?
S.Lott
+1  A: 

By setting the noclasses attribute to True, only inline styles will be generated. Here's a snippet that does the job just fine:


formatter = HtmlFormatter(style=MyStyle)
formatter.noclasses = True
print highlight(content,PythonLexer(),formatter)
Geo
A: 

Pass full=True to the HtmlFormatter constructor.

Ignacio Vazquez-Abrams