最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Use Jinja2 macros in Sphinx documentation - Stack Overflow

programmeradmin1浏览0评论

I am attempting to use Jinja2 from Sphinx to allow Jinja2 macros in my rst files. The Jinja2 macro invocations are being ignored and the macro invocation is rendered as simple text in the HTML output. For example, I want to use a macro in the file index.rst. The index.rst file looks something like this:

{{ Abbr("URL", "Uniform Resource Locator") }}

where Abbr is the name of the macro. I believe this is the correct way to invoke a Jinja2 macro. How do I get Sphinx to run Jinja2 against my source files?

I have incorporated a template file in the Sphinx _templates_ directory that looks like this:

{% extends !index.html %}
{# import the template file containing the macros #}
{% import MA.tmpl as tmpl %}

The file containing the macro is stored in the _templates_ directory and looks like this:

{# This macro is used in Sphinx-based documents and generates an HTML
   abbreviation that can be further controlled using CSS #}
{% macro Abbr(abbreviation, expansion) -%}
   <abbr title="{{ expansion }}>{{ abbreviation }}</abbr>
{%- endmacro %}
发布评论

评论列表(0)

  1. 暂无评论