# HG changeset patch # User Tero Marttila # Date 1234178340 -7200 # Node ID 1f182913b1f2d27ec914e02f5b5efc689cd1c283 # Parent 8157c41b3236924f04653efa524366eef44b5a23 href-ize urls diff -r 8157c41b3236 -r 1f182913b1f2 log_formatter.py --- a/log_formatter.py Mon Feb 09 12:59:03 2009 +0200 +++ b/log_formatter.py Mon Feb 09 13:19:00 2009 +0200 @@ -2,8 +2,7 @@ Format LogLines into some other representation """ -# for escape -import cgi +import re, xml.sax.saxutils from log_line import LogTypes @@ -72,6 +71,29 @@ abstract +class BaseHTMLFormatter (object) : + """ + Implements some HTML-formatting utils + """ + + URL_REGEXP = re.compile(r"http://\S+") + + def _process_links (self, line) : + """ + Processed the rendered line, adding in 's for things that look like URLs, returning the new line. + + The line should already be escaped + """ + + def _encode_url (match) : + # encode URL + url_html = match.group(0) + url_link = xml.sax.saxutils.unescape(url_html) + + return '%(url_html)s' % dict(url_link=url_link, url_html=url_html) + + return self.URL_REGEXP.sub(_encode_url, line) + class IrssiTextFormatter (LogFormatter) : """ Implements format_txt for irssi-style output @@ -88,7 +110,7 @@ # using __TYPES yield self._format_line_text(line, self.__FMT, full_timestamps) -class IrssiFormatter (IrssiTextFormatter) : +class IrssiFormatter (IrssiTextFormatter, BaseHTMLFormatter) : """ Implements plain black-and-white irssi-style formatting """ @@ -107,7 +129,13 @@ # format using IrssiTextFormatter for line in self.format_txt(lines, full_timestamps) : # escape HTML - yield cgi.escape(line) + line = xml.sax.saxutils.escape(line) + + # process links + line = self._process_links(line) + + # yield + yield line # close pre yield "" diff -r 8157c41b3236 -r 1f182913b1f2 static/irclogs.css --- a/static/irclogs.css Mon Feb 09 12:59:03 2009 +0200 +++ b/static/irclogs.css Mon Feb 09 13:19:00 2009 +0200 @@ -252,7 +252,7 @@ width: 15em; } -input[type=submit] { +fieldset input[type=submit] { width: 8em; } @@ -283,3 +283,7 @@ text-align: left; } +/* Log lines */ +div#lines a { + color: black; +} diff -r 8157c41b3236 -r 1f182913b1f2 templates/channel_date.tmpl --- a/templates/channel_date.tmpl Mon Feb 09 12:59:03 2009 +0200 +++ b/templates/channel_date.tmpl Mon Feb 09 13:19:00 2009 +0200 @@ -2,8 +2,4 @@
${channel.title} :: Logs for ${h.fmt_date(date)}
-% for line in lines : -${line} -% endfor - - +<%include file="lines.tmpl" /> diff -r 8157c41b3236 -r 1f182913b1f2 templates/channel_search.tmpl --- a/templates/channel_search.tmpl Mon Feb 09 12:59:03 2009 +0200 +++ b/templates/channel_search.tmpl Mon Feb 09 13:19:00 2009 +0200 @@ -32,7 +32,5 @@ % else :
${channel.title} :: Search '${search_query}'
-% for line in lines: -${line} -% endfor +<%include file="lines.tmpl" /> % endif diff -r 8157c41b3236 -r 1f182913b1f2 templates/channel_view.tmpl --- a/templates/channel_view.tmpl Mon Feb 09 12:59:03 2009 +0200 +++ b/templates/channel_view.tmpl Mon Feb 09 13:19:00 2009 +0200 @@ -2,8 +2,4 @@
${channel.title} :: Last ${count} lines
-% for line in lines : -${line} -% endfor - - +<%include file="lines.tmpl" /> diff -r 8157c41b3236 -r 1f182913b1f2 templates/lines.tmpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/lines.tmpl Mon Feb 09 13:19:00 2009 +0200 @@ -0,0 +1,5 @@ +
+% for line in lines: +${line} +% endfor +