當前位置: 首頁>>代碼示例>>Python>>正文


Python nodes.General方法代碼示例

本文整理匯總了Python中docutils.nodes.General方法的典型用法代碼示例。如果您正苦於以下問題:Python nodes.General方法的具體用法?Python nodes.General怎麽用?Python nodes.General使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在docutils.nodes的用法示例。


在下文中一共展示了nodes.General方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_simple_html_directive

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import General [as 別名]
def create_simple_html_directive(name, pre, post,
                                 has_content=True, match_titles=False):
    """
    Creates a node class, directive class and setup method for the given
    parameters.

    :param name: String representing the RST directive to add.
    :param pre: String representing HTML to come before directive content.
    :param post: String representing HTML to come after directive content.
    :param has_content: Boolean indicating whether the directive accepts
        a content block.
    :param match_titles: Boolean indicating whether headings and titles may
        be included in the block contained within this directive.
    """
    node_class = type(
        name.replace('-', '_'), (nodes.General, nodes.Element), {}
    )

    def visit_html(self, node):
        self.body.append(pre)

    def depart_html(self, node):
        self.body.append(post)

    def run_directive(self):
        node = node_class()
        if has_content:
            text = self.content
            self.state.nested_parse(text, self.content_offset,
                                    node, match_titles=match_titles)
        # FIXME: This should add more stuff.
        self.state.document.settings.record_dependencies.add(__file__)
        return [node]

    directive_class = type(name.title() + 'Directive', (Directive,), {
        "has_content": has_content,
        "run": run_directive,
    })

    def setup(app):
        app.add_node(node_class,
                     html=(visit_html, depart_html))
        app.add_directive(name, directive_class)

    return node_class, directive_class, setup 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:47,代碼來源:_simple.py


注:本文中的docutils.nodes.General方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。