# To understand this beast, read /usr/share/doc/python2.5-doc/html/lib/module-re.html :-)
reLink = re.compile(r'''
- \[\[ # Begin of link
- (?=[^!]) # Don't fire for macros
+ \[\[ # Begin of link
+ (?=[^!]) # Don't fire for macros
(?:
- ([^\]\|]+) # 1: link text
- \| # followed by '|'
- )? # optional
- ([^\n\r\]#]+) # 2: page to link to
+ ([^\]\|]+) # 1: link text
+ \| # followed by '|'
+ )? # optional
+ ([^\n\r\]#]+) # 2: page to link to
(
- \# # '#', beginning of anchor
- [^\s\]]+ # 3: anchor text, doesn't contain spaces or ']'
- )? # optional
- \]\] # end of link
+ \# # '#', beginning of anchor
+ [^\s\]]+ # 3: anchor text, doesn't contain spaces or ']'
+ )? # optional
+ \]\] # end of link
''', re.VERBOSE)
def do_link(m):
link = m.group(2).replace("\n", " ")
anchor = m.group(3) or ""
if link.find(".") == -1:
- #link = link.tolower()
for f in files:
file = files[f]
+ if not file.has_key("linktitle"):
+ continue
if file.title == link or \
file.linktitle == link or \
os.path.splitext(os.path.basename(file.path))[0] == link:
link = get_link_from(get_current_file().linktitle, file.linktitle)
#print "LINK: '%s' '%s'" % (text, link)
break
- # TODO: validate link
+ if not text:
+ text = link
+ # validate link
+ # TODO: validating local files still not working
+ if not link.startswith("http:") and not link.endswith(".html") and not link.endswith(".png"):
+ file = get_current_file()
+ warning("%s: unknown link to '%s'" % (file.rel_path, link) )
return '<a href="%s%s">%s</a>' % (link, anchor, text)
m = reLink.search(s)
if m:
print "link:", s
- print " name:", m.group(1)
- print " link:", m.group(2)
- print " anchor:", m.group(3)
+ print " name:", m.group(1)
+ print " link:", m.group(2)
+ print " anchor:", m.group(3)
else:
print "No link:", s
res = reLink.sub(do_link, s)
print "", res
-#test_link()
-#test_sub()
-
-
-
@set_hook("linkify")
def linkify(params):
- return reLink.sub(do_link, params.file.contents)
+ params.file.contents = reLink.sub(do_link, params.file.contents)