-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread.py
More file actions
29 lines (24 loc) · 756 Bytes
/
read.py
File metadata and controls
29 lines (24 loc) · 756 Bytes
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
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import Terminal256Formatter
def isplit(gen):
started = False
collected = []
for line in gen:
if line.startswith('# START'):
started = True
continue
if not started:
continue
if line.startswith('next_()'):
yield collected
collected = []
else:
collected.append(line.rstrip())
if len(collected):
yield collected
def main():
with open('deck.py') as f:
for group in isplit(f):
code = "\n".join([line for line in group if line != "\n"])
yield highlight(code, PythonLexer(), Terminal256Formatter())