微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使自定义 Sphinx 指令过程成为文本中的包含语句

如何解决如何使自定义 Sphinx 指令过程成为文本中的包含语句

我希望我的自定义指令能够处理文本块中的 RST .. include:: 语句。这就是我的 run 方法中的内容,但它似乎不起作用:

class my_content_node(nodes.General,nodes.Element):
    pass

class MyDirective(Only):
    option_spec = Only.option_spec
    # this enables content in the directive
    has_content = True

    def run(self):
        env = self.state.document.settings.env
        node = my_content_node()  # creating my custom node to control the html writers
        content_output = Only.run(self)
        node.setup_child(content_output[0])
        node.children.append(name_node)
        node.children.append(content_output[0])
        return [node]

def visit_fragment_node(self,node):
    self.body.append(self.starttag(node,'div','',CLASS='mydirective'))

def depart_content_node(self,node):
    self.body.append('</div>')

def setup(app):
  app.add_directive('mydirective',MyDirective)
  app.add_node(my_content_node,html=(visit_content_node,depart_content_node))
  return {
        'version': '0.1','parallel_read_safe': True,'parallel_write_safe': True,}

我有以下 RST 内容时,它会失败

.. mydirective::
   :name: directive-name

   .. include:: ./my_directive_related.rst

语句 Only.run(self) 不处理 .. include:: 语句。 content_output 是一个空列表。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。