#!/usr/bin/python3 import sys import re lines = ''.join(sys.stdin.readlines()) link = re.compile("(\[[^\]]*\]\([^\)]+\))") link_split = re.compile("\[([^\]]*)\]\(([^\)]+)\)") marginnotes = re.compile("(\[\^.*?\]\:.*?\n\n)",re.DOTALL|re.MULTILINE) _lines = marginnotes.sub("",lines) lines = _lines links = link.findall(lines) i = 1 for _link in links: lines = lines.replace(_link, "[%s]"%i) i+=1 i = 1 lines += "\n\n" for _link in links: ls = link_split.match(_link) lines += "=> %s %s\n"%(ls[2],ls[1]) i += 1 sys.stdout.write(lines)