Home | History | Annotate | Download | only in doc
      1 #!/usr/bin/env python
      2 
      3 from __future__ import print_function
      4 import fileinput
      5 import re
      6 import sys
      7 
      8 
      9 rc_script = re.compile(r'\s*(.*\S)?\s*')
     10 
     11 def parse_dict(filename):
     12 	links = {}
     13 	for line in open(filename, 'r'):
     14 		m = re.match('^([^=]+)=([^\n]+)$', line);
     15 		if not m:
     16 			continue
     17 		name = m.group(1)
     18 		value = m.group(2)
     19 
     20 		# strip leading and trailing whitespace
     21 		m = rc_script.match(name)
     22 		if m:
     23 			name = m.group(1)
     24 
     25 		# skip special names
     26 		if name == '':
     27 			continue
     28 		if name == '\\':
     29 			continue
     30 
     31 		links[name] = "<a href=\"" + value + "\" class=\"dg\">" + name + "</a>"
     32 	return links
     33 
     34 links = parse_dict(sys.argv[1])
     35 
     36 def translate(match):
     37 	return links[match.group(1)]
     38 
     39 # match for all names, with word boundaries \b
     40 rc = re.compile(r'\b(' + '|'.join(map(re.escape, sorted(links, reverse=True))) + r')\b')
     41 
     42 for line in open(sys.argv[2], 'r'):
     43 	print(rc.sub(translate, line), end='')
     44