Skip to content

Commit

Permalink
html.py: format add-on description for HTML
Browse files Browse the repository at this point in the history
The description text does not get rendered very well on a webpage. One
solution might be to use pre-wrap/word-wrap in the CSS, but due to
differences between browsers, that's a can of worms (at least for me, I'm
not a web pro).

So, the not-so-elegant solution is to add <br/> to every line.

URLs are also not linked in the plain text. Although in modern browsers
you can select the text and right-click, it's still convenient to turn
them into actual links.
  • Loading branch information
groggyd88 committed Apr 25, 2014
1 parent b058f29 commit c85af75
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion data/tools/addon_manager/html.py
Expand Up @@ -134,8 +134,21 @@ def w(x):
else: w(('<td>%s</td>') % type)
w(('<td><img alt="%s" src="%s" width="72px" height="72px"/>'
) % (icon, imgurl))
described = v("description", "(no description)")
if described != "(no description)":
shift = 0
for urlref in re.finditer(r'(?<![">])http://[\w./?&=%~-]+', described):
described = described[:urlref.start()+shift] + '<a href="' + urlref.group(0) + '">' + urlref.group(0) + "</a>" + described[urlref.end()+shift:]
shift += 15 + len(urlref.group(0))
shift = 0
for wesurl in re.finditer(r'(?<![\w>"/])(forums?|r|R|wiki)\.wesnoth\.org/[\w./?&=%~-]+', described):
described = described[:wesurl.start()+shift] + '<a href="http://' + wesurl.group(0) + '">' + wesurl.group(0) + "</a>" + described[wesurl.end()+shift:]
shift += 22 + len(wesurl.group(0))
described = re.sub(r"\n", "\n<br/>", described)
if sys.platform != "win32":
described = re.sub(r"\r(?!\n)", r"\r<br/>", described)
w('<div class="desc"><b>%s</b><br/>%s</div></td>' % (
name, v("description", "(no description)")))
name, described))
w("<td><b>%s</b><br/>" % name)
w("Version: %s<br/>" % v("version", "unknown"))
w("Author: %s</td>" % v("author", "unknown"))
Expand Down

0 comments on commit c85af75

Please sign in to comment.