You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
521 B
26 lines
521 B
4 months ago
|
#!/usr/bin/env python
|
||
|
|
||
|
import fileinput
|
||
|
import re
|
||
|
import sys
|
||
|
|
||
|
refs = {}
|
||
|
complete_file = ""
|
||
|
|
||
|
for line in open(sys.argv[1], 'r'):
|
||
|
complete_file += line
|
||
|
|
||
|
for m in re.findall('\[\[(.+)\]\]\n=+ ([^\n]+)', complete_file):
|
||
|
ref, title = m
|
||
|
refs["<<" + ref + ">>"] = "<<" + ref + ", " + title + ">>"
|
||
|
|
||
|
def translate(match):
|
||
|
try:
|
||
|
return refs[match.group(0)]
|
||
|
except KeyError:
|
||
|
return ""
|
||
|
|
||
|
rc = re.compile('|'.join(map(re.escape, sorted(refs, reverse=True))))
|
||
|
for line in open(sys.argv[1], 'r'):
|
||
|
print rc.sub(translate, line),
|