Merge pull request #7196 from tk0miya/7195_todo_incorrect_doctree_resolved

Fix #7195: todo: emit doctree-resolved event with non-document node incorrectly
This commit is contained in:
Takeshi KOMIYA 2020-02-22 17:49:12 +09:00 committed by GitHub
commit 51ac09d7b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

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

View File

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