style.css,html.py: use <pre> instead of <br/>; re.sub instead of re.finditer
After looking into it some more, I think I've figured out how to handle <pre> in the CSS. So, use that, when description has more than one line. Also, go to re.sub for turning URLs into links. The version of Python I was testing my code on wasn't properly handling backreferences in the replacement string when in the form "\#", causing me to use finditer instead of sub. But I've discovered that it does handle backreferences in the form "\g<#>". So switch to much simpler re.sub code.
This commit is contained in:
parent
7ef7d14978
commit
faf82bed92
2 changed files with 13 additions and 11 deletions
|
@ -136,17 +136,10 @@ unit packs, terrain packs, music packs, etc. Usually a (perhaps optional) depend
|
|||
) % (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)
|
||||
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)
|
||||
if "\n" in described:
|
||||
described = "<pre>" + described + "</pre>"
|
||||
w('<div class="desc"><b>%s</b><br/>%s</div></td>' % (
|
||||
name, described))
|
||||
w("<td><b>%s</b><br/>" % name)
|
||||
|
|
|
@ -89,6 +89,15 @@ td:hover div.desc {
|
|||
padding: 8px;
|
||||
}
|
||||
|
||||
pre {
|
||||
white-space: pre-wrap; /* css-3 */
|
||||
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
|
||||
white-space: -pre-wrap; /* Opera 4-6 */
|
||||
white-space: -o-pre-wrap; /* Opera 7 */
|
||||
word-wrap: break-word; /* Internet Explorer 5.5+ */
|
||||
font: inherit
|
||||
}
|
||||
|
||||
/* tables */
|
||||
table.tablesorter {
|
||||
width: 100%;
|
||||
|
|
Loading…
Add table
Reference in a new issue