diff --git a/CHANGES b/CHANGES index 7eae4be41d0..d0b6bc4f499 100644 --- a/CHANGES +++ b/CHANGES @@ -80,6 +80,8 @@ Bugs fixed bulding texinfo document * #10000: LaTeX: glossary terms with common definition are rendered with too much vertical whitespace +* #10318: ``:prepend:`` option of :rst:dir:`literalinclude` directive does not + work with ``:dedent:`` option Testing -------- diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py index dc44ed31485..9437fe9a5e5 100644 --- a/sphinx/directives/code.py +++ b/sphinx/directives/code.py @@ -224,9 +224,9 @@ def read(self, location: Tuple[str, int] = None) -> Tuple[str, int]: self.start_filter, self.end_filter, self.lines_filter, + self.dedent_filter, self.prepend_filter, - self.append_filter, - self.dedent_filter] + self.append_filter] lines = self.read_file(self.filename, location=location) for func in filters: lines = func(lines, location=location) diff --git a/tests/test_directive_code.py b/tests/test_directive_code.py index 98a9aa89940..cc73c426ce2 100644 --- a/tests/test_directive_code.py +++ b/tests/test_directive_code.py @@ -251,6 +251,19 @@ def test_LiteralIncludeReader_dedent(literal_inc_path): "\n") +@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows") +def test_LiteralIncludeReader_dedent_and_append_and_prepend(literal_inc_path): + # dedent: 2 + options = {'lines': '9-11', 'dedent': 2, 'prepend': 'class Foo:', 'append': '# comment'} + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) + content, lines = reader.read() + assert content == ("class Foo:\n" + " def baz():\n" + " pass\n" + "\n" + "# comment\n") + + @pytest.mark.xfail(os.name != 'posix', reason="Not working on windows") def test_LiteralIncludeReader_tabwidth(testroot): # tab-width: 4