• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2
3from __future__ import print_function
4
5import re
6import sys
7
8refs = {}
9complete_file = ""
10
11for line in open(sys.argv[1], "r"):
12    complete_file += line
13
14for m in re.findall("\\[\\[(.+)\\]\\]\n=+ ([^\n]+)", complete_file):
15    ref, title = m
16    refs["<<" + ref + ">>"] = "<<" + ref + ", " + title + ">>"
17
18
19def translate(match):
20    try:
21        return refs[match.group(0)]
22    except KeyError:
23        return ""
24
25
26rc = re.compile("|".join(map(re.escape, sorted(refs, reverse=True))))
27for line in open(sys.argv[1], "r"):
28    print(rc.sub(translate, line), end="")
29