diff --git a/sphinx/ext/viewcode.py b/sphinx/ext/viewcode.py index d8b649da9..d79df22e0 100644 --- a/sphinx/ext/viewcode.py +++ b/sphinx/ext/viewcode.py @@ -104,6 +104,7 @@ def collect_pages(app): # now that we have code lines (starting at index 1), insert anchors for # the collected tags (HACK: this only works if the tag boundaries are # properly nested!) + maxindex = len(lines) for name, docname in used.iteritems(): type, start, end = tags[name] backlink = urito(pagename, docname) + '#' + modname + '.' + name @@ -111,7 +112,7 @@ def collect_pages(app): '
%s' % (name, backlink, _('[docs]')) + lines[start]) - lines[end - 1] += '
' + lines[min(end - 1, maxindex)] += '' # try to find parents (for submodules) parents = [] parent = modname