Created
April 5, 2016 15:06
-
-
Save TomDLT/1645afb6a0b2cb713416d1740d96cc4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import os | |
# find existing links | |
matches = [] | |
with open('whats_new.rst', 'r') as f: | |
for line in f.readlines(): | |
m = re.search('`[A-Za-z üéö@.ä-]*`_', line) | |
if m is not None: | |
matches.append(m.group(0)) | |
# remove empty link and duplicates | |
matches = list(set(matches)) | |
matches.remove('``_') | |
# find names without links and add a link | |
with open('whats_new.rst', 'r') as f: | |
out = open('whats_new.rst2', "w") | |
for line in f.readlines(): | |
for match in matches: | |
line = re.sub(' ' + match[1:-2], ' ' + match, line) | |
out.write(line) | |
out.close() | |
os.rename('whats_new.rst2', 'whats_new.rst') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment