etherpump/linkify.py
2015-07-23 18:09:20 +02:00

30 lines
525 B
Python

from __future__ import print_function
import re, sys
def urlify (t):
return t.replace(" ", "_") + ".html"
def linkify (src, urlify=urlify):
collect = []
def s (m):
contents = m.group(1)
collect.append(contents)
link = urlify(contents)
return "[[<a class=\"wikilink\" href=\"{0}\">{1}</a>]]".format(link, contents)
src = re.sub(r"\[\[([\w_\- ]+?)\]\]", s, src)
return (src, collect)
if __name__ == "__main__":
src = sys.stdin.read()
src, links = linkify(src)
for l in links:
print (l)
print (src)