diff --git a/sphinx/ext/viewcode.py b/sphinx/ext/viewcode.py index 0446fa94159..ffd90f1549e 100644 --- a/sphinx/ext/viewcode.py +++ b/sphinx/ext/viewcode.py @@ -262,14 +262,16 @@ def collect_pages(app: Sphinx) -> Generator[tuple[str, dict[str, Any], str], Non lines[0:1] = [before + '
', after] # nothing to do for the last line; it always starts withanyway # now that we have code lines (starting at index 1), insert anchors for - # the collected tags + # the collected tags (HACK: this only works if the tag boundaries are + # properly nested!) + max_index = len(lines) - 1 for name, docname in used.items(): type, start, end = tags[name] backlink = urito(pagename, docname) + '#' + refname + '.' + name lines[start] = ( - '{_("[docs]")}\n' + - lines[start]) + f'