fixed bugs, and extended unit test to catch them again if they reappear

This commit is contained in:
Jeppe Pihl
2014-10-06 10:58:03 +02:00
parent a3745cfb5e
commit 0b0cf82a75
2 changed files with 5 additions and 4 deletions

View File

@@ -9,6 +9,7 @@
import sys
import codecs
import os
from difflib import unified_diff
from docutils import nodes
@@ -286,7 +287,7 @@ class LiteralInclude(Directive):
for line_number, line in enumerate(lines):
if not use and startafter and startafter in line:
if 'lineno-match' in self.options:
linenostart += line_number + 2
linenostart += line_number + 1
use = True
elif use and endbefore and endbefore in line:
break
@@ -296,8 +297,8 @@ class LiteralInclude(Directive):
if 'lineno-match' in self.options:
# handle that preceding, empty lines ('\n') are removed.
for line in lines[linenostart-1:]:
if line != '\n':
for line in lines:
if line != os.linesep:
break
linenostart += 1

View File

@@ -8,7 +8,7 @@ Literal Includes with Line Numbers Matching
.. literalinclude:: literal.inc
:language: python
:lines: 6,7,8-9
:lines: 5-6,7,8-9
:lineno-match:
.. literalinclude:: literal.inc