forked from csev/py4e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmhack.py
50 lines (39 loc) · 945 Bytes
/
mhack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Remove blank lines before and after a glossary definition
lines = list()
while True:
try:
line = raw_input()
except:
break
lines.append(line)
blank = True
colon = False
newlines = list()
for pos in range(len(lines)):
if pos < 5 or pos > len(lines)-5 :
newlines.append(lines[pos])
continue
line = lines[pos]
if line == '' :
blank = True
continue
prev = lines[pos-1]
nxt = lines[pos+1]
if line.startswith(':') :
# ignore any outstanding blank lines
blank = False
colon = True
newlines.append(line)
continue
# Ignore any outstanding blank lines
if colon and line.startswith('\\') :
colon = False
blank = False
newlines.append(line)
continue
if blank:
newlines.append('')
blank = False
newlines.append(line)
for line in newlines:
print line