doc: convert refcounting directive to a class
Directive functions are no longer supported in Sphinx-3.0 but directive classes have been supported since early 1.x
This commit is contained in:
parent
73ccec0601
commit
798d40c3f3
@ -24,8 +24,8 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
|
from docutils.parsers.rst import Directive
|
||||||
|
|
||||||
class refcounting(nodes.emphasis): pass
|
|
||||||
|
|
||||||
def visit(self, node):
|
def visit(self, node):
|
||||||
self.visit_emphasis(node)
|
self.visit_emphasis(node)
|
||||||
@ -40,16 +40,25 @@ def html_depart(self, node):
|
|||||||
self.body.append('</em>')
|
self.body.append('</em>')
|
||||||
|
|
||||||
|
|
||||||
def refcounting_directive(name, arguments, options, content, lineno,
|
class refcounting(nodes.emphasis):
|
||||||
content_offset, block_text, state, state_machine):
|
pass
|
||||||
if arguments[0] == 'borrow':
|
|
||||||
text = 'Return value: Borrowed reference.'
|
class refcounting_directive(Directive):
|
||||||
elif arguments[0] == 'new':
|
has_content = False
|
||||||
text = 'Return value: New reference.'
|
required_arguments = 1
|
||||||
else:
|
optional_arguments = 0
|
||||||
raise Error('Valid arguments: new, borrow')
|
final_argument_whitespace = False
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
if self.arguments[0] == 'borrow':
|
||||||
|
text = 'Return value: Borrowed reference.'
|
||||||
|
elif self.arguments[0] == 'new':
|
||||||
|
text = 'Return value: New reference.'
|
||||||
|
else:
|
||||||
|
raise Error('Valid arguments: new, borrow')
|
||||||
|
|
||||||
|
return [refcounting(text, text)]
|
||||||
|
|
||||||
return [refcounting(text, text)]
|
|
||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
app.add_node(refcounting,
|
app.add_node(refcounting,
|
||||||
@ -57,4 +66,4 @@ def setup(app):
|
|||||||
latex=(visit, depart),
|
latex=(visit, depart),
|
||||||
text=(visit, depart),
|
text=(visit, depart),
|
||||||
man=(visit, depart))
|
man=(visit, depart))
|
||||||
app.add_directive('refcounting', refcounting_directive, 0, (1, 0, 0))
|
app.add_directive('refcounting', refcounting_directive)
|
||||||
|
Loading…
Reference in New Issue
Block a user