Fix #6742: end-before option of literalinclude skips first line

This commit is contained in:
Takeshi KOMIYA 2019-10-20 15:44:19 +09:00
parent ec8d41b237
commit 39b166b6b9
3 changed files with 12 additions and 1 deletions

View File

@ -7,6 +7,9 @@ Dependencies
Incompatible changes Incompatible changes
-------------------- --------------------
* #6742: ``end-before`` option of :rst:dir:`literalinclude` directive does not
match the first line of the code block.
Deprecated Deprecated
---------- ----------

View File

@ -348,7 +348,7 @@ class LiteralIncludeReader:
return lines[:lineno + 1] return lines[:lineno + 1]
else: else:
if lineno == 0: if lineno == 0:
return [] pass # end-before ignores first line
else: else:
return lines[:lineno] return lines[:lineno]
if inclusive is True: if inclusive is True:

View File

@ -206,6 +206,14 @@ def test_LiteralIncludeReader_missing_start_and_end(literal_inc_path):
content, lines = reader.read() content, lines = reader.read()
def test_LiteralIncludeReader_end_before(literal_inc_path):
options = {'end-before': 'nclud'} # *nclud* matches first and third lines.
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == ("# Literally included file using Python highlighting\n"
"\n")
@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows") @pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_prepend(literal_inc_path): def test_LiteralIncludeReader_prepend(literal_inc_path):
options = {'lines': '1', 'prepend': 'Hello', 'append': 'Sphinx'} options = {'lines': '1', 'prepend': 'Hello', 'append': 'Sphinx'}