0

我在 Java 中使用 Pygments;我在我的项目中使用它,它解析非常慢,需要 4 秒多。Pygments 的官方文档在这里http://pygments.org/docs/java

我的代码:

PythonInterpreter interpreter = new PythonInterpreter();

// Set a variable with the content you want to work with
interpreter.set("code", code);

// Simple use Pygments as you would in Python
interpreter.exec("from pygments import highlight\n"
    + "from pygments.lexers import PythonLexer\n"
    + "from pygments.formatters import HtmlFormatter\n"
    + "\nresult = highlight(code, PythonLexer(), HtmlFormatter())");

// Get the result that has been set in a variable
System.out.println(interpreter.get("result", String.class));
4

0 回答 0