当前位置: 首页>>代码示例>>Python>>正文


Python transforms.Transform方法代码示例

本文整理汇总了Python中docutils.transforms.Transform方法的典型用法代码示例。如果您正苦于以下问题:Python transforms.Transform方法的具体用法?Python transforms.Transform怎么用?Python transforms.Transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在docutils.transforms的用法示例。


在下文中一共展示了transforms.Transform方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from docutils import transforms [as 别名]
# 或者: from docutils.transforms import Transform [as 别名]
def __init__(self, *args, **kwargs):
        transforms.Transform.__init__(self, *args, **kwargs)
        self.reporter = self.document.reporter
        self.config = self.default_config.copy()
        try:
            new_cfg = self.document.settings.env.config.recommonmark_config
            self.config.update(new_cfg)
        except AttributeError:
            pass

        # Deprecation notices
        # TODO move this check to an extension pattern, and only call once
        if self.config.get('enable_auto_doc_ref', False):
            self.reporter.warning(
                'AutoStructify option "enable_auto_doc_ref" is deprecated')

    # set to a high priority so it can be applied first for markdown docs 
开发者ID:readthedocs,项目名称:recommonmark,代码行数:19,代码来源:transform.py

示例2: publish_secondary_doctree

# 需要导入模块: from docutils import transforms [as 别名]
# 或者: from docutils.transforms import Transform [as 别名]
def publish_secondary_doctree(text, main_tree, source_path):

    # This is a hack so the text substitutions defined
    # in the document are available when we process the cover
    # page. See Issue 322
    dt = main_tree
    # Add substitutions  from the main doctree
    class addSubsts(Transform):
        default_priority = 219

        def apply(self):
            self.document.substitution_defs.update(dt.substitution_defs)
            self.document.substitution_names.update(dt.substitution_names)

    # Use an own reader to modify transformations done.
    class Reader(standalone.Reader):
        def get_transforms(self):
            default = standalone.Reader.get_transforms(self)
            return default + [
                addSubsts,
            ]

    # End of Issue 322 hack

    return docutils.core.publish_doctree(text, reader=Reader(), source_path=source_path) 
开发者ID:rst2pdf,项目名称:rst2pdf,代码行数:27,代码来源:createpdf.py

示例3: apply

# 需要导入模块: from docutils import transforms [as 别名]
# 或者: from docutils.transforms import Transform [as 别名]
def apply(self):
        language = languages.get_language(self.document.settings.language_code,
                                          self.document.reporter)
        for node in self.document.traverse(nodes.Admonition):
            node_name = node.__class__.__name__
            # Set class, so that we know what node this admonition came from.
            node['classes'].append(node_name)
            if not isinstance(node, nodes.admonition):
                # Specific admonition.  Transform into a generic admonition.
                admonition = nodes.admonition(node.rawsource, *node.children,
                                              **node.attributes)
                title = nodes.title('', language.labels[node_name])
                admonition.insert(0, title)
                node.replace_self(admonition) 
开发者ID:skarlekar,项目名称:faces,代码行数:16,代码来源:writer_aux.py

示例4: promote_title

# 需要导入模块: from docutils import transforms [as 别名]
# 或者: from docutils.transforms import Transform [as 别名]
def promote_title(self, node):
        """
        Transform the following tree::

            <node>
                <section>
                    <title>
                    ...

        into ::

            <node>
                <title>
                ...

        `node` is normally a document.
        """
        # Type check
        if not isinstance(node, nodes.Element):
            raise TypeError('node must be of Element-derived type.')

        # `node` must not have a title yet.
        assert not (len(node) and isinstance(node[0], nodes.title))
        section, index = self.candidate_index(node)
        if index is None:
            return None

        # Transfer the section's attributes to the node:
        # NOTE: Change second parameter to False to NOT replace
        #       attributes that already exist in node with those in
        #       section
        # NOTE: Remove third parameter to NOT copy the 'source'
        #       attribute from section
        node.update_all_atts_concatenating(section, True, True)

        # setup_child is called automatically for all nodes.
        node[:] = (section[:1]        # section title
                   + node[:index]     # everything that was in the
                                      # node before the section
                   + section[1:])     # everything that was in the section
        assert isinstance(node[0], nodes.title)
        return 1 
开发者ID:skarlekar,项目名称:faces,代码行数:44,代码来源:frontmatter.py

示例5: promote_subtitle

# 需要导入模块: from docutils import transforms [as 别名]
# 或者: from docutils.transforms import Transform [as 别名]
def promote_subtitle(self, node):
        """
        Transform the following node tree::

            <node>
                <title>
                <section>
                    <title>
                    ...

        into ::

            <node>
                <title>
                <subtitle>
                ...
        """
        # Type check
        if not isinstance(node, nodes.Element):
            raise TypeError('node must be of Element-derived type.')

        subsection, index = self.candidate_index(node)
        if index is None:
            return None
        subtitle = nodes.subtitle()

        # Transfer the subsection's attributes to the new subtitle
        # NOTE: Change second parameter to False to NOT replace
        #       attributes that already exist in node with those in
        #       section
        # NOTE: Remove third parameter to NOT copy the 'source'
        #       attribute from section
        subtitle.update_all_atts_concatenating(subsection, True, True)

        # Transfer the contents of the subsection's title to the
        # subtitle:
        subtitle[:] = subsection[0][:]
        node[:] = (node[:1]       # title
                   + [subtitle]
                   # everything that was before the section:
                   + node[1:index]
                   # everything that was in the subsection:
                   + subsection[1:])
        return 1 
开发者ID:skarlekar,项目名称:faces,代码行数:46,代码来源:frontmatter.py

示例6: promote_title

# 需要导入模块: from docutils import transforms [as 别名]
# 或者: from docutils.transforms import Transform [as 别名]
def promote_title(self, node):
        """
        Transform the following tree::

            <node>
                <section>
                    <title>
                    ...

        into ::

            <node>
                <title>
                ...

        `node` is normally a document.
        """
        # Type check
        if not isinstance(node, nodes.Element):
            raise TypeError, 'node must be of Element-derived type.'

        # `node` must not have a title yet.
        assert not (len(node) and isinstance(node[0], nodes.title))
        section, index = self.candidate_index(node)
        if index is None:
            return None

        # Transfer the section's attributes to the node:
        # NOTE: Change second parameter to False to NOT replace
        #       attributes that already exist in node with those in
        #       section
        # NOTE: Remove third parameter to NOT copy the 'source'
        #       attribute from section
        node.update_all_atts_concatenating(section, True, True)

        # setup_child is called automatically for all nodes.
        node[:] = (section[:1]        # section title
                   + node[:index]     # everything that was in the
                                      # node before the section
                   + section[1:])     # everything that was in the section
        assert isinstance(node[0], nodes.title)
        return 1 
开发者ID:skarlekar,项目名称:faces,代码行数:44,代码来源:frontmatter.py

示例7: promote_subtitle

# 需要导入模块: from docutils import transforms [as 别名]
# 或者: from docutils.transforms import Transform [as 别名]
def promote_subtitle(self, node):
        """
        Transform the following node tree::

            <node>
                <title>
                <section>
                    <title>
                    ...

        into ::

            <node>
                <title>
                <subtitle>
                ...
        """
        # Type check
        if not isinstance(node, nodes.Element):
            raise TypeError, 'node must be of Element-derived type.'

        subsection, index = self.candidate_index(node)
        if index is None:
            return None
        subtitle = nodes.subtitle()

        # Transfer the subsection's attributes to the new subtitle
        # NOTE: Change second parameter to False to NOT replace
        #       attributes that already exist in node with those in
        #       section
        # NOTE: Remove third parameter to NOT copy the 'source'
        #       attribute from section
        subtitle.update_all_atts_concatenating(subsection, True, True)

        # Transfer the contents of the subsection's title to the
        # subtitle:
        subtitle[:] = subsection[0][:]
        node[:] = (node[:1]       # title
                   + [subtitle]
                   # everything that was before the section:
                   + node[1:index]
                   # everything that was in the subsection:
                   + subsection[1:])
        return 1 
开发者ID:skarlekar,项目名称:faces,代码行数:46,代码来源:frontmatter.py


注:本文中的docutils.transforms.Transform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。