$ pygmentize -O full -O style=native -o test.html test.py
Pygments zu installieren:
$ easy_install Pygments
Sie es als Bibliothek verwenden können.
from pygments import highlight
from pygments.lexers import guess_lexer
from pygments.formatters import HtmlFormatter
code = '#!/usr/bin/python\nprint "Hello World!"'
lexer = guess_lexer(code) # or just pygments.lexers.PythonLexer()
formatter = HtmlFormatter(noclasses=True, nowrap=True, lineseparator="<br>\n")
print highlight(code, lexer, formatter)
Ausgang:
<span style="color: #408080; font-style: italic">#!/usr/bin/python</span><br>
<span style="color: #008000; font-weight: bold">print</span>
<span style="color: #BA2121">"Hello World!"</span><br>
(hinzugefügt Leerzeichen für Klarheit)
als HTML:
#/usr/bin/python
Druck " Hallo Welt! "
Gee, ich wusste nicht über Syntax Highlighter – Xolve
In vielen Fällen ist die Syntaxhighlighter groß. Es gibt eine Wordpress-Plugin-Version, die ich ziemlich ausführlich in meinem Blog verwende. –
+1 Ich wusste auch nicht –