2

Sphinx でカスタム ロール/ディレクティブを作成しています。テキスト文字列を reStructuredText として解釈するノードを挿入する必要があります。これを行う方法はありますか?

このソースを見つけましたhttp://agateau.com/2015/docutils-snippetsは、クラスを使用docutils.nodesしてプログラムでdoctreeフラグメントを構築する方法を示しています。

class BulletList(Directive):
    def run(self):
        fruits = ['Apples', 'Oranges', 'Bananas']

        lst = nodes.bullet_list()
        for fruit in fruits:
            item = nodes.list_item()
            lst += item
            item += nodes.paragraph(text=fruit)

        return [lst]

私がやりたいことは次のようなものです

:myrole:`this is *really* cool|trade|`

conf.py でこれを行うことにより:

def myrole(name, rawtext, text, lineno, inliner, options={}, content=[]):
    # somehow convert the "text" parameter into docutils nodes
    # by interpreting it as RST
    nodes = ???? what goes here ???
    return nodes, []

def setup(app):
    app.add_role('myrole', myrole)
4

1 に答える 1