python - 如何避免 evoque 中的 html 转义

标签 python

我尝试对我的极光模板进行一些颜色编码, 但我得到的 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/

相关文章:

python - 使用多列连接 Pandas 数据框

python - 如何从 xlsm 文件复制宏并将其插入到另一个 xlsm 文件中?

python - 是否可以从 Django 服务器端检测浏览器版本?

python - 如何从 ctypes 数组中获取 ctypes 类型对象

python - python中的中值下采样

python - Django DecimalField 在保存时生成 "quantize result has too many digits for current context"错误

python - 属性错误 : 'str' object has no attribute 'sort'

python - SQLAlchemy + MYSQL 唯一字符串列被截断

python - SublimeLinter 不遵守 "pep8_ignore"设置

python - 在 Matplotlib 中如何防止图像出现在屏幕上? Python