html.py: hone regexes for URL linking

First, a couple of extraneous quotes were left in the second regex around
"</a>".

Second, it is possible that a period or question mark could be used to end
a sentence, rather than be part of the URL. So check that these characters
are followed by an alphanumeric character to make them part of the URL.
This commit is contained in:
Groggy Dice 2014-05-15 23:55:21 -04:00
parent da388ce21a
commit e3adf001a8

View file

@ -137,8 +137,8 @@ Unit packs, terrain packs, music packs, etc. Usually a (perhaps optional) depend
) % (icon, imgurl))
described = v("description", "(no description)")
if described != "(no description)":
described = re.sub(r'(?<![">])http://[\w./?&=%~-]+', r'<a href="\g<0>">\g<0></a>', described)
described = re.sub(r'(?<![\w>"/])(forums?|r|R|wiki)\.wesnoth\.org[\w./?&=%~-]+', r'<a href="http://\g<0>">\g<0>"</a>"', described)
described = re.sub(r'(?<![">])http://([\w/=%~-]|[.?&]\w)+', r'<a href="\g<0>">\g<0></a>', described)
described = re.sub(r'(?<![\w>"/])(forums?|r|R|wiki)\.wesnoth\.org([\w/=%~-]|[.?&]\w)*', r'<a href="http://\g<0>">\g<0></a>', described)
w('<div class="desc"><b>%s</b><pre>%s</pre></div></td>' % (
name, described))
w("<td><b>%s</b><br/>" % name)