Fix #7195: todo: emit doctree-resolved event with non-document node incorrectly

This commit is contained in:
Takeshi KOMIYA 2020-02-22 17:32:41 +09:00
parent 723c4491c7
commit 29db44a354
2 changed files with 8 additions and 2 deletions

View File

@ -21,6 +21,7 @@ Bugs fixed
* #7189: autodoc: classmethod coroutines are not detected
* #7183: intersphinx: ``:attr:`` reference to property is broken
* #6244, #6387: html search: Search breaks/hangs when built with dirhtml builder
* #7195: todo: emit doctree-resolved event with non-document node incorrectly
Testing

View File

@ -28,7 +28,7 @@ from sphinx.environment import BuildEnvironment
from sphinx.errors import NoUri
from sphinx.locale import _, __
from sphinx.util import logging, texescape
from sphinx.util.docutils import SphinxDirective
from sphinx.util.docutils import SphinxDirective, new_document
from sphinx.util.nodes import make_refnode
from sphinx.writers.html import HTMLTranslator
from sphinx.writers.latex import LaTeXTranslator
@ -159,6 +159,7 @@ class TodoListProcessor:
def process(self, doctree: nodes.document, docname: str) -> None:
todos = sum(self.domain.todos.values(), []) # type: List[todo_node]
document = new_document('')
for node in doctree.traverse(todolist):
if not self.config.todo_include_todos:
node.parent.remove(node)
@ -175,7 +176,11 @@ class TodoListProcessor:
new_todo['ids'].clear()
# (Recursively) resolve references in the todo content
self.env.resolve_references(new_todo, todo['docname'], self.builder) # type: ignore # NOQA
#
# Note: To resolve references, it is needed to wrap it with document node
document += new_todo
self.env.resolve_references(document, todo['docname'], self.builder)
document.remove(new_todo)
content.append(new_todo)
todo_ref = self.create_todo_reference(todo, docname)