1
# -*- coding: utf-8 -*-
2
# This is a hack of the builtin todo extension, to make the todo_list more user friendly
4
from sphinx.ext.todo import *
5
from docutils.parsers.rst import directives
12
def process_todo_nodes(app, doctree, fromdocname):
13
if not app.config['todo_include_todos']:
14
for node in doctree.traverse(todo_node):
15
node.parent.remove(node)
17
# Replace all todolist nodes with a list of the collected todos.
18
# Augment each todo with a backlink to the original location.
21
if not hasattr(env, 'todo_all_todos'):
22
env.todo_all_todos = []
25
# remove the item that was added in the constructor, since I'm tired of
26
# reading through docutils for the proper way to construct an empty list
29
lists.append(nodes.bullet_list("", nodes.Text('','')));
30
lists[i].remove(lists[i][0])
31
lists[i].set_class('todo_list')
33
for node in doctree.traverse(todolist):
34
if not app.config['todo_include_todos']:
38
for todo_info in env.todo_all_todos:
39
para = nodes.paragraph()
40
filename = env.doc2path(todo_info['docname'], base=None)
43
newnode = nodes.reference('', '')
45
link = _('%s, line %d') % (filename, todo_info['lineno']);
46
innernode = nodes.emphasis(link, link)
47
newnode['refdocname'] = todo_info['docname']
50
newnode['refuri'] = app.builder.get_relative_uri(
51
fromdocname, todo_info['docname'])
52
newnode['refuri'] += '#' + todo_info['target']['refid']
54
# ignore if no URI can be determined, e.g. for LaTeX output
57
newnode.append(innernode)
59
para.set_class('todo_link')
61
todo_entry = todo_info['todo']
63
env.resolve_references(todo_entry, todo_info['docname'], app.builder)
65
item = nodes.list_item('', para)
66
todo_entry[1].set_class('details')
68
comment = todo_entry[1]
70
m = re.match(r"^P(\d)", comment.astext())
73
priority = int(m.group(1))
74
if (priority < 0): priority = 1
75
if (priority > 5): priority = 5
77
item.set_class('todo_p' + str(priority))
78
todo_entry.set_class('todo_p' + str(priority))
82
lists[priority-1].insert(0, item)
85
node.replace_self(lists)
88
app.add_config_value('todo_include_todos', False, False)
90
app.add_node(todolist)
91
app.add_node(todo_node,
92
html=(visit_todo_node, depart_todo_node),
93
latex=(visit_todo_node, depart_todo_node),
94
text=(visit_todo_node, depart_todo_node))
96
app.add_directive('todo', Todo)
97
app.add_directive('todolist', TodoList)
98
app.connect('doctree-read', process_todos)
99
app.connect('doctree-resolved', process_todo_nodes)
100
app.connect('env-purge-doc', purge_todos)