本文整理匯總了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