summaryrefslogtreecommitdiffstats
path: root/doc/resolve-asciidoc-refs.py
blob: 541874736d9026900fd81d8080af1ecfc907df88 (plain)
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
#!/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),