From 29db44a35400fd123714c70a11da204cf86cf232 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 22 Feb 2020 17:32:41 +0900 Subject: [PATCH] Fix #7195: todo: emit doctree-resolved event with non-document node incorrectly --- CHANGES | 1 + sphinx/ext/todo.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index d20693b67aa..f70b0bd32b3 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/sphinx/ext/todo.py b/sphinx/ext/todo.py index 69aaaf8b2e2..c5cacc43751 100644 --- a/sphinx/ext/todo.py +++ b/sphinx/ext/todo.py @@ -28,7 +28,7 @@ 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 @@ def __init__(self, app: Sphinx, 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] + document = new_document('') for node in doctree.traverse(todolist): if not self.config.todo_include_todos: node.parent.remove(node) @@ -175,7 +176,11 @@ def process(self, doctree: nodes.document, docname: str) -> None: 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)