aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorPierce Lopez <pierce.lopez@gmail.com>2020-08-07 01:54:45 -0400
committerPierce Lopez <pierce.lopez@gmail.com>2020-08-07 01:54:45 -0400
commit798d40c3f3e0700501de1588274b69e2b128ad7c (patch)
tree118a64af5e59355150a2825f62b9e46838310442 /doc
parent73ccec06010b2dc5dcd56f4a9b30d08e2bf1148c (diff)
downloadjansson-798d40c3f3e0700501de1588274b69e2b128ad7c.zip
jansson-798d40c3f3e0700501de1588274b69e2b128ad7c.tar.gz
jansson-798d40c3f3e0700501de1588274b69e2b128ad7c.tar.bz2
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
Diffstat (limited to 'doc')
-rw-r--r--doc/ext/refcounting.py31
1 files changed, 20 insertions, 11 deletions
diff --git a/doc/ext/refcounting.py b/doc/ext/refcounting.py
index bba2684..e72c481 100644
--- a/doc/ext/refcounting.py
+++ b/doc/ext/refcounting.py
@@ -24,8 +24,8 @@
"""
from docutils import nodes
+from docutils.parsers.rst import Directive
-class refcounting(nodes.emphasis): pass
def visit(self, node):
self.visit_emphasis(node)
@@ -40,16 +40,25 @@ def html_depart(self, node):
self.body.append('</em>')
-def refcounting_directive(name, arguments, options, content, lineno,
- content_offset, block_text, state, state_machine):
- if arguments[0] == 'borrow':
- text = 'Return value: Borrowed reference.'
- elif arguments[0] == 'new':
- text = 'Return value: New reference.'
- else:
- raise Error('Valid arguments: new, borrow')
+class refcounting(nodes.emphasis):
+ pass
+
+class refcounting_directive(Directive):
+ has_content = False
+ required_arguments = 1
+ optional_arguments = 0
+ 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):
app.add_node(refcounting,
@@ -57,4 +66,4 @@ def setup(app):
latex=(visit, depart),
text=(visit, depart),
man=(visit, depart))
- app.add_directive('refcounting', refcounting_directive, 0, (1, 0, 0))
+ app.add_directive('refcounting', refcounting_directive)