我尝试对我的极光模板进行一些颜色编码, 但我得到的 html 已经用 lt-gt 转义了
我读到应该有类似不再引用类的东西 但我一直没能找到 evoque.quoted 包
我的目标是不要从模板中转义 html,而是“真实”。
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
from evoque.domain import Domain
import os
tmpl="""
$begin{code}
${codyfy(evoque(name=label), lang=label.split()[0][1:])}
$end{code}
$begin{c 0}
int main(void){printf("hello world");return 0;}
$end{c 0}
$begin{python 0}
print "hello world"
$end{python 0}
$evoque{#code, label="#c 0"}
$evoque{#code, label="#python 0"}
"""
td = Domain(os.path.abspath("."))
def codyfy(src,lang="python"):
return highlight(src,get_lexer_by_name(lang, stripall=True),HtmlFormatter())
td.set_on_globals('codyfy',codyfy)
td.set_template("testtmpl", src=tmpl, from_string=True)
t = td.get_template("testtmpl")
print t.evoque()
最佳答案
您是否尝试过使用raw=True
?请参阅:
我以前没有使用过 Qpy,但也许这篇文章会有所帮助:
Defining custom quoted-no-more classes
[...] It is also highly recommended to download and install the Qpy unicode templating utility that provides the qpy.xml Quoted-No-More class for automatic input escaping. [...]
关于python - 如何避免 evoque 中的 html 转义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1285134/