made an online code highlighting project, strong python as always did not disappoint me, a powerful pygments module can be in a variety of (many) languages code highlighting
Here's a look at this:
The first installation is simple, using Easy_install to install:
Easy_install pygments
After the installation we use, Python's simplicity will not let everyone down:
From pygments.lexers import pythonlexverfrom pygments.formatters import htmlformatterfrom pygments Import Highlightformatter = Htmlformatter (encoding= ' utf-8 ', style = ' emacs ', Linenos = True) code = Highlight (' print ' Hello, world "', Pythonlexer (), formatter) Print code
Results
'
1 |
Print "Hello, world"\ n \ n |
'
This is simple to highlight the code, of course, if you do the above, and then input the content into a file to view, certainly big call pit dad, because there is no highlight, because the default is not output CSS We also want to get CSS added to the HTML:
CSS = Formatter.get_style_defs ()
Then the CSS content and the above HTML to write to the HTML file to see the highlighted code (don't tell me you don't know where CSS should be placed)