我想使用pygments动态地突出显示代码—基本上是一个巨大的JSON对象列表。我试了一下:
from pygments.lexers import JsonLexer
from pygments.formatters import HtmlFormatter
from pygments import highlight
import StringIO
f = StringIO.StringIO()
f.write('a')
f.seek(0)
print highlight(f, JsonLexer(), HtmlFormatter())
这给了我以下错误:
^{pr2}$显然这是错误的接口。什么才是正确的?在
highlight要求f是一个具有decode属性的字符串。StringIO没有这个属性。在
^{1}$用一根直的绳子。在
^{pr2}$相关问题 更多 >
编程相关推荐