##// END OF EJS Templates
Remove leading empty lines...
Robin Gustafsson -
Show More
@@ -18,6 +18,19 b' import warnings'
18 18
19 19 _indent_re = re.compile(r'^[ \t]+')
20 20
21 def leading_empty_lines(lines):
22 """Remove leading empty lines
23
24 If the leading lines are empty or contain only whitespace, they will be
25 removed.
26 """
27 if not lines:
28 return lines
29 for i, line in enumerate(lines):
30 if line and not line.isspace():
31 return lines[i:]
32 return lines
33
21 34 def leading_indent(lines):
22 35 """Remove leading indentation.
23 36
@@ -510,6 +523,7 b' class TransformerManager:'
510 523 """
511 524 def __init__(self):
512 525 self.cleanup_transforms = [
526 leading_empty_lines,
513 527 leading_indent,
514 528 classic_prompt,
515 529 ipython_prompt,
@@ -86,3 +86,31 b' def test_leading_indent():'
86 86 for sample, expected in [INDENT_SPACES, INDENT_TABS]:
87 87 nt.assert_equal(ipt2.leading_indent(sample.splitlines(keepends=True)),
88 88 expected.splitlines(keepends=True))
89
90 LEADING_EMPTY_LINES = ("""\
91 \t
92
93 if True:
94 a = 3
95
96 b = 4
97 """, """\
98 if True:
99 a = 3
100
101 b = 4
102 """)
103
104 ONLY_EMPTY_LINES = ("""\
105 \t
106
107 """, """\
108 \t
109
110 """)
111
112 def leading_empty_lines():
113 for sample, expected in [LEADING_EMPTY_LINES, ONLY_EMPTY_LINES]:
114 nt.assert_equal(
115 ipt2.leading_empty_lines(sample.splitlines(keepends=True)),
116 expected.splitlines(keepends=True))
General Comments 0
You need to be logged in to leave comments. Login now