diff --git a/doc/Manual.txt b/doc/Manual.txt index 55f0051..2fe82ba 100644 --- a/doc/Manual.txt +++ b/doc/Manual.txt @@ -169,21 +169,19 @@ adjust and have MeetBot re-process the logs later. release. #link - Add a link to the minutes. The URL must be the first thing on the - line, separated by a space from the rest of the line, and it will be - properly hyperlinked. This command is automatically detected if the line - starts with http:, https:, mailto:, and some other common protocols - defined in the ``UrlProtocols`` configuration variable. Examples:: + + Add a link to the minutes. The URL will be properly detected within + the line in most cases - the URL can't contain spaces. This command + is automatically detected if the line starts with http:, https:, + mailto:, and some other common protocols defined in the + ``UrlProtocols`` configuration variable. Examples:: < MrBeige> #link http://wiki.debian.org/MeetBot/ is the main page < MrBeige> http://wiki.debian.org/MeetBot/ is the main page - - Both of these two examples are equivalent, and will hyperlink - properly. The first example below won't hyperlink properly, the - second one won't be automatically detected:: - < MrBeige> #link the main page is http://wiki.debian.org/MeetBot/ - < MrBeige> the main page is http://wiki.debian.org/MeetBot/ + so go there + < MrBeige> the main page is http://wiki.debian.org/MeetBot/ so go + there. (This will NOT be detected automatically) diff --git a/ircmeeting/items.py b/ircmeeting/items.py index 7463585..1109fb0 100644 --- a/ircmeeting/items.py +++ b/ircmeeting/items.py @@ -30,6 +30,7 @@ ### import os +import re import time import writers @@ -73,10 +74,9 @@ class _BaseItem(object): replacements[name] = getattr(self, name) replacements['nick'] = escapewith(replacements['nick']) replacements['link'] = self.logURL(M) - if 'line' in replacements: - replacements['line'] = escapewith(replacements['line']) - if 'topic' in replacements: - replacements['topic'] = escapewith(replacements['topic']) + for key in ('line', 'prefix', 'suffix', 'topic'): + if key in replacements: + replacements[key] = escapewith(replacements[key]) if 'url' in replacements: replacements['url_quoteescaped'] = \ escapewith(self.url.replace('"', "%22")) @@ -228,24 +228,40 @@ class Rejected(GenericItem): class Link(_BaseItem): itemtype = 'LINK' html_template = """%(time)s - %(itemtype)s%(nick)s%(starthtml)s%(url_readable)s %(line)s%(endhtml)s + %(itemtype)s%(nick)s%(starthtml)s%(prefix)s%(url_readable)s%(suffix)s%(endhtml)s """ - #html2_template = ("""%(itemtype)s: %(starthtml)s%(url_readable)s %(line)s%(endhtml)s """ - # """(%(nick)s, %(time)s)""") - #html2_template = ("""%(itemtype)s: %(starthtml)s%(url_readable)s %(line)s%(endhtml)s """ - # """(%(nick)s, %(time)s)""") - html2_template = ("""%(starthtml)s%(url_readable)s %(line)s%(endhtml)s """ + html2_template = ("""%(starthtml)s%(prefix)s%(url_readable)s%(suffix)s%(endhtml)s """ """""" """(%(nick)s, """ """%(time)s)""" """""") - rst_template = """*%(itemtype)s*: %(startrst)s%(url)s %(line)s%(endrst)s (%(rstref)s_)""" - text_template = """%(itemtype)s: %(starttext)s%(url)s %(line)s%(endtext)s (%(nick)s, %(time)s)""" - mw_template = """''%(itemtype)s:'' %(startmw)s%(url)s %(line)s%(endmw)s (%(nick)s, %(time)s)""" - def __init__(self, nick, line, linenum, time_): + rst_template = """*%(itemtype)s*: %(startrst)s%(prefix)s%(url)s%(suffix)s%(endrst)s (%(rstref)s_)""" + text_template = """%(itemtype)s: %(starttext)s%(prefix)s%(url)s%(suffix)s%(endtext)s (%(nick)s, %(time)s)""" + mw_template = """''%(itemtype)s:'' %(startmw)s%(prefix)s%(url)s%(suffix)s%(endmw)s (%(nick)s, %(time)s)""" + def __init__(self, nick, line, linenum, time_, M): self.nick = nick ; self.linenum = linenum self.time = time.strftime("%H:%M:%S", time_) - self.url, self.line = (line+' ').split(' ', 1) + self.line = line + + protocols = M.config.UrlProtocols + protocols = '|'.join(re.escape(p) for p in protocols) + protocols = '(?:'+protocols+')' + # This is gross. + # (.*?) - any prefix, non-greedy + # (%s//[^\s]+ - protocol://... until the next space + # (? #startmeeting + 20:13:50 #link prefix http://site1.com suffix + 20:13:50 http://site2.com suffix + 20:13:50 ftp://ftpsite1.com suffix + 20:13:50 #link prefix ftp://ftpsite2.com suffix + 20:13:50 irc://ircsite1.com suffix + 20:13:50 mailto://a@mail.com suffix + 20:13:50 #endmeeting + """ + M = process_meeting(script) + results = M.save()['.html'] + assert re.search(r'prefix.*href.*http://site1.com.*suffix', + results), "URL missing 1" + assert re.search(r'href.*http://site2.com.*suffix', + results), "URL missing 2" + assert re.search(r'href.*ftp://ftpsite1.com.*suffix', + results), "URL missing 3" + assert re.search(r'prefix.*href.*ftp://ftpsite2.com.*suffix', + results), "URL missing 4" + assert re.search(r'href.*mailto://a@mail.com.*suffix', + results), "URL missing 5" + def t_css(self): """Runs all CSS-related tests. """ diff --git a/tests/test-script-1.log.txt b/tests/test-script-1.log.txt index bd7cb16..7f46176 100644 --- a/tests/test-script-1.log.txt +++ b/tests/test-script-1.log.txt @@ -64,7 +64,15 @@ # links 20:13:50 #topic Links 20:13:50 #link http://test.zgib.net +20:13:50 #link ftp://test.zgib.net " +20:13:50 #link mailto://a@bla"h.com 20:13:50 #link http://test.zgib.net/&testpage +20:13:50 #link prefix http://test.zgib.net/&testpage suffix +20:13:50 #link prefix ftp://test.zg"ib.net/&testpage suffix +20:13:50 #link prefix mailto://a@blah.com&testpage suffix +20:13:50 #link prefix http://google.com/. suffix +20:13:50 #link prefix (http://google.com/) suffix + # accents 20:13:50 #topic Character sets