Lektor的插件开发

Arm*_*her 2 python lektor

我正在尝试开发一个reStructuredText插件并做一些基本的错误.

我的插件对象如下所示:

class RSTPlugin(Plugin):
    name = 'RST'
    description = 'RST plugin'

    def on_setup_env(self, **extra):
        self.env.jinja_env.filters['markdown'] = \
            jinja2.contextfilter(lambda ctx, *a, **kw: RST(*a, **kw))
Run Code Online (Sandbox Code Playgroud)

现在:on_setup_env调用该函数.请注意,我正在替换markdown dict条目(暂时).但是当我运行lektor时,原来的Markdown类被调用而不是我的RST类.

Arm*_*her 5

这是Lektor问题跟踪器中出现的问题:https://github.com/lektor/lektor/issues/77

答案是Lektor不对字段类型使用Jinja过滤器.相反,必须实现类似这样的类型:https://www.getlektor.com/docs/api/db/type/

然而,这需要目前正在开发的Lektor 2.0.