Skip to content

Commit

Permalink
Merge pull request #10323 from tk0miya/10318_literalinclude_prepend_a…
Browse files Browse the repository at this point in the history
…nd_dedent

Fix #10318: literalinclude: :prepend: option working with :dedent:
  • Loading branch information
tk0miya committed Apr 3, 2022
2 parents 312efdb + e571479 commit 7bdc11e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -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
--------
Expand Down
4 changes: 2 additions & 2 deletions sphinx/directives/code.py
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_directive_code.py
Expand Up @@ -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
Expand Down

0 comments on commit 7bdc11e

Please sign in to comment.