forked from fastai/fastai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmd_expander.py
executable file
·37 lines (22 loc) · 1003 Bytes
/
md_expander.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
import sys
import re
def expand(filename):
f = open(filename, "r")
contents = f.read()
regex_inside = r"\{\{(.*?)\}\}"
regex_outside = r"(^|\}\})(.*?)(\{\{|$)"
within = re.finditer(regex_inside, contents, re.MULTILINE | re.DOTALL)
outside = re.finditer(regex_outside, contents, re.MULTILINE | re.DOTALL)
for matchNum, match in enumerate(within):
for groupNum in range(0, len(match.groups())):
group = match.group(1)
if group.startswith("class"):
classname = re.search(r" (.*?),", group).groups()[0]
params = re.search(r",(.*)", group).groups()[0]
print('<h2 id="' + classname + '" class="class">Class: ' + classname + '(<span class="params">' + params + '</span></h2>')
print (match.group(1))
# split = re.split(regex_inside, contents)
#
# for i, item in enumerate(split):
if __name__ == '__main__':
expand(sys.argv[1])