Jinja2 テンプレートで目次と文末脚注を作成したいと考えています。これらのタスクをどのように達成できますか?
たとえば、次のようなテンプレートが必要です。
{% block toc %}
{# ... the ToC goes here ... #}
{% endblock %}
{% include "some other file with content.jnj" %}
{% block endnotes %}
{# ... the endnotes go here ... #}
{% endblock %}
には次のsome other file with content.jnj
ようなコンテンツがあります。
{% section "One" %}
Title information for Section One (may be quite long); goes in Table of Contents
...
Content of section One
{% section "Two" %}
Title information of Section Two (also may be quite long)
<a href="#" id="en1">EndNote 1</a>
<script type="text/javsacript">...(may be reasonably long)
</script> {# ... Everything up to here is included in the EndNote #}
私が「かなり/適度に長いかもしれない」と言っているところでは、マクロまたはグローバル関数への引数として引用符で囲むことは合理的ではないと言っている.
Jinja2のフレームワーク内で、これに対応できるパターンがあるかどうか疑問に思っています。
私の最初の考えは、拡張機能を作成して、セクションとエンドノートのブロックを作成できるようにすることです。
{% section "One" %}
Title information goes here.
{% endsection %}
{% endnote "one" %}
<a href="#">...</a>
<script> ... </script>
{% endendnote %}
次に、グローバル関数 (Jinja2 環境で渡す) を用意します。
{{ table_of_contents() }}
{% include ... %}
{{ endnotes() }}
ただし、これは文末脚注には機能しますが、目次には何かによる 2 回目のパスが必要になると思います。
読んでくれてありがとう。ご意見やご感想をお寄せいただければ幸いです。
ブライアン