#!/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),

@@ -16,16 +16,55 @@
 python%0A%0A
+from __future__ import print_function%0A%0A
 import f
@@ -527,17 +527,17 @@
 :%0A%09print
- 
+(
 rc.sub(t
@@ -552,9 +552,17 @@
 , line),
+ end='')
 %0A

fix python2-ism in "doc/resolve-asciidoc-refs.py"