-
Notifications
You must be signed in to change notification settings - Fork 3
/
format.py
31 lines (23 loc) · 961 Bytes
/
format.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
#!/usr/bin/env python3
import re
def format(s, pattern, replacement):
# Capture the groups from the pattern and replace them in the replacement string
return re.sub(pattern, replacement, s)
if __name__ == '__main__':
with open("README_RAW.md", "r") as f:
lines = f.readlines()
patterns = [
r"\| ([0-9]+) \|",
r"\| (https\:\/\/github\.com.*) \|",
r"\| (https\:\/\/.*) \|"
]
replacements = [
r'| <a href="https://pubmed.ncbi.nlm.nih.gov/\1/" target="_blank">\1</a> |',
r'| <a href="\1" target="_blank">GitHub</a> |',
r'| <a href="\1" target="_blank">Link</a> |'
]
for j in range(len(lines)):
for i in range(len(patterns)):
lines[j] = format(lines[j], patterns[i], replacements[i])
with open("README.md", "w") as f:
f.write("".join(lines))