forked from bwnyasse/dv-workshop-for-opencommit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkdown_parser.py
More file actions
26 lines (21 loc) · 721 Bytes
/
Copy pathmarkdown_parser.py
File metadata and controls
26 lines (21 loc) · 721 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
from models import Step, Codelab
def parse_markdown(file_path):
with open(file_path, 'r') as file:
lines = file.readlines()
title = ''
steps = []
current_label = ''
current_content = ''
for line in lines:
if line.startswith('# '):
title = line.strip('# ').strip()
elif line.startswith('## '):
if current_label:
steps.append(Step(current_label, current_content.strip()))
current_label = line.strip('## ').strip()
current_content = ''
else:
current_content += line
if current_label:
steps.append(Step(current_label, current_content.strip()))
return Codelab(title, steps)