diff --git a/CHANGES b/CHANGES index df2f3d89c..bb6a15806 100644 --- a/CHANGES +++ b/CHANGES @@ -32,6 +32,7 @@ Bugs fixed * #4258: napoleon: decorated special methods are not shown * #7715: LaTeX: ``numfig_secnum_depth > 1`` leads to wrong figure links * #7846: html theme: XML-invalid files were generated +* #7894: gettext: Wrong source info is shown when using rst_epilog * #7869: :rst:role:`abbr` role without an explanation will show the explanation from the previous abbr role * C and C++, removed ``noindex`` directive option as it did diff --git a/sphinx/util/rst.py b/sphinx/util/rst.py index 33acaa0e7..e93849b70 100644 --- a/sphinx/util/rst.py +++ b/sphinx/util/rst.py @@ -103,6 +103,11 @@ def prepend_prolog(content: StringList, prolog: str) -> None: def append_epilog(content: StringList, epilog: str) -> None: """Append a string to content body as epilog.""" if epilog: - content.append('', '', 0) + if 0 < len(content): + source, lineno = content.info(-1) + else: + source = '' + lineno = 0 + content.append('', source, lineno + 1) for lineno, line in enumerate(epilog.splitlines()): content.append(line, '', lineno) diff --git a/tests/test_parser.py b/tests/test_parser.py index 4b0cf17a3..f76e004d6 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -50,7 +50,7 @@ def test_RSTParser_prolog_epilog(RSTStateMachine, app): (content, _), _ = RSTStateMachine().run.call_args assert list(content.xitems()) == [('dummy.rst', 0, 'hello Sphinx world'), ('dummy.rst', 1, 'Sphinx is a document generator'), - ('', 0, ''), + ('dummy.rst', 2, ''), ('', 0, 'this is rst_epilog'), ('', 1, 'good-bye reST!')] diff --git a/tests/test_util_rst.py b/tests/test_util_rst.py index 6f55c5698..dd78fe5ba 100644 --- a/tests/test_util_rst.py +++ b/tests/test_util_rst.py @@ -32,7 +32,7 @@ def test_append_epilog(app): assert list(content.xitems()) == [('dummy.rst', 0, 'hello Sphinx world'), ('dummy.rst', 1, 'Sphinx is a document generator'), - ('', 0, ''), + ('dummy.rst', 2, ''), ('', 0, 'this is rst_epilog'), ('', 1, 'good-bye reST!')]