-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-tests.py
37 lines (27 loc) · 906 Bytes
/
make-tests.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
import json
def main():
tests = []
# read stdin line by line
for line in sys.stdin:
# process <h1> lines
if line.startswith('<h1>'):
# extract the title and its fragment name
fragment_name, title = re.match(r'^.*href="#([^"]*)".*a>(.*)</h1>$', line).groups()
# remove digit suffix from fragment name
match = re.match(r'^(.*)(-\d+)$', fragment_name)
if match is not None:
fragment_name = match.group(1)
# remove HTML entities from title
title = title.replace('<', '<')
title = title.replace('>', '>')
# create the test
test = {
'in': title,
'out': fragment_name
}
tests.append(test)
print json.dumps(tests)
if __name__ == '__main__':
main()