As you may or may not know, you can generate a color syntax-higlighted HTML file from a PHP source file using php -s.
I know about the syntaxhighlighter that Stackoverflow uses and that's not really what I'm looking for. I'm looking for something will generate HTML output without Javascript.
Does anyone know of something equivalent to php -s for Python?$ pygmentize -O full -O style=native -o test.html test.py
To install Pygments:
$ easy_install Pygments
You can use it as a library.
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)
Output:
<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>
(added whitespace for clarity)
As html:
#!/usr/bin/python
print
"Hello World!"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With