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


Python docutils.SphinxDirective方法代码示例

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


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

示例1: create_directive_from_renderer

# 需要导入模块: from sphinx.util import docutils [as 别名]
# 或者: from sphinx.util.docutils import SphinxDirective [as 别名]
def create_directive_from_renderer(renderer_cls):
    """Create rendering directive from a renderer class."""

    class _RenderingDirective(SphinxDirective):
        required_arguments = 1                  # path to openapi spec
        final_argument_whitespace = True        # path may contain whitespaces
        option_spec = dict(
            {
                'encoding': directives.encoding,    # useful for non-ascii cases :)
            },
            **renderer_cls.option_spec
        )

        def run(self):
            relpath, abspath = self.env.relfn2path(directives.path(self.arguments[0]))

            # URI parameter is crucial for resolving relative references. So we
            # need to set this option properly as it's used later down the
            # stack.
            self.options.setdefault('uri', 'file://%s' % abspath)

            # Add a given OpenAPI spec as a dependency of the referring
            # reStructuredText document, so the document is rebuilt each time
            # the spec is changed.
            self.env.note_dependency(relpath)

            # Read the spec using encoding passed to the directive or fallback to
            # the one specified in Sphinx's config.
            encoding = self.options.get('encoding', self.config.source_encoding)
            spec = _get_spec(abspath, encoding)
            return renderer_cls(self.state, self.options).render(spec)

    return _RenderingDirective 
开发者ID:sphinx-contrib,项目名称:openapi,代码行数:35,代码来源:directive.py


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