您可能知道或不知道,您可以使用php -s从PHP源文件生成颜色语法高亮的HTML文件.
我知道Stackoverflow使用的syntaxhighlighter,这不是我真正想要的.我正在寻找能够在没有Javascript的情况下生成HTML输出的东西.
有谁知道的东西等同于PHP - 小号为Python?
jfs.. 12
$ pygmentize -O full -O style=native -o test.html test.py
要安装Pygments:
$ easy_install Pygments
您可以将其用作库.
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="
\n") print highlight(code, lexer, formatter)
输出:
#!/usr/bin/python
print "Hello World!"
(为了清晰起见,添加了空格)
作为HTML:
#!/ usr/bin/python
print"Hello World!"
$ pygmentize -O full -O style=native -o test.html test.py
要安装Pygments:
$ easy_install Pygments
您可以将其用作库.
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="
\n") print highlight(code, lexer, formatter)
输出:
#!/usr/bin/python
print "Hello World!"
(为了清晰起见,添加了空格)
作为HTML:
#!/ usr/bin/python
print"Hello World!"