summaryrefslogtreecommitdiffstats
path: root/doc/development/tutorials/examples/todo.py
diff options
context:
space:
mode:
Diffstat (limited to 'doc/development/tutorials/examples/todo.py')
-rw-r--r--doc/development/tutorials/examples/todo.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/doc/development/tutorials/examples/todo.py b/doc/development/tutorials/examples/todo.py
index 15368f4..2baac5c 100644
--- a/doc/development/tutorials/examples/todo.py
+++ b/doc/development/tutorials/examples/todo.py
@@ -1,8 +1,10 @@
from docutils import nodes
from docutils.parsers.rst import Directive
+from sphinx.application import Sphinx
from sphinx.locale import _
from sphinx.util.docutils import SphinxDirective
+from sphinx.util.typing import ExtensionMetadata
class todo(nodes.Admonition, nodes.Element):
@@ -22,13 +24,11 @@ def depart_todo_node(self, node):
class TodolistDirective(Directive):
-
def run(self):
return [todolist('')]
class TodoDirective(SphinxDirective):
-
# this enables content in the directive
has_content = True
@@ -57,8 +57,7 @@ def purge_todos(app, env, docname):
if not hasattr(env, 'todo_all_todos'):
return
- env.todo_all_todos = [todo for todo in env.todo_all_todos
- if todo['docname'] != docname]
+ env.todo_all_todos = [todo for todo in env.todo_all_todos if todo['docname'] != docname]
def merge_todos(app, env, docnames, other):
@@ -90,37 +89,40 @@ def process_todo_nodes(app, doctree, fromdocname):
for todo_info in env.todo_all_todos:
para = nodes.paragraph()
filename = env.doc2path(todo_info['docname'], base=None)
- description = (
- _('(The original entry is located in %s, line %d and can be found ') %
- (filename, todo_info['lineno']))
+ description = _(
+ '(The original entry is located in %s, line %d and can be found '
+ ) % (filename, todo_info['lineno'])
para += nodes.Text(description)
# Create a reference
newnode = nodes.reference('', '')
innernode = nodes.emphasis(_('here'), _('here'))
newnode['refdocname'] = todo_info['docname']
- newnode['refuri'] = app.builder.get_relative_uri(
- fromdocname, todo_info['docname'])
+ newnode['refuri'] = app.builder.get_relative_uri(fromdocname, todo_info['docname'])
newnode['refuri'] += '#' + todo_info['target']['refid']
newnode.append(innernode)
para += newnode
para += nodes.Text('.)')
# Insert into the todolist
- content.append(todo_info['todo'])
- content.append(para)
+ content.extend((
+ todo_info['todo'],
+ para,
+ ))
node.replace_self(content)
-def setup(app):
+def setup(app: Sphinx) -> ExtensionMetadata:
app.add_config_value('todo_include_todos', False, 'html')
app.add_node(todolist)
- app.add_node(todo,
- html=(visit_todo_node, depart_todo_node),
- latex=(visit_todo_node, depart_todo_node),
- text=(visit_todo_node, depart_todo_node))
+ app.add_node(
+ todo,
+ html=(visit_todo_node, depart_todo_node),
+ latex=(visit_todo_node, depart_todo_node),
+ text=(visit_todo_node, depart_todo_node),
+ )
app.add_directive('todo', TodoDirective)
app.add_directive('todolist', TodolistDirective)