我有一种类似Lisp的语言,想要在Sphinx代码段文档中使用Pygments进行高亮显示。我的方法是通过使用NameHighlightFilter扩展现有的CommonLispLexer来添加内置名称。 然而,它没有起作用,所以我肯定忽略了一些显而易见的东西。我已经在我的conf.py文件中添加了以下内容:
def setup(app):
from sphinx.highlighting import lexers
from pygments.lexers import CommonLispLexer
from pygments.token import Name
from pygments.filters import NameHighlightFilter
tl_lexer = CommonLispLexer()
tl_lexer.add_filter(NameHighlightFilter(
names=['define-function', 'define-macro',
'define-variable', 'define-constant'],
tokentype=Name.Builtin,
))
app.add_lexer('tl', tl_lexer)
highlight_language = 'tl'
但是NameHighlightFilter没有效果。代码块被突出显示,就好像它们是Lisp一样,但我的新内置名称没有特殊的突出显示。
add_filter
,define-function
仍然被标记为Name.Variable
而不是Name.Builtin
。 - Jennifer Smith