Display links as footnotes
Rather than including them in the text that gets wrapped. This prevents links from getting split, potentially breaking them. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
c8c40f1682
commit
5d4cab62e5
|
@ -25,10 +25,20 @@ def _text_parse_channel(text):
|
||||||
res = re.sub("<#%s(.*?)>" % chid, "#%s" % name, res)
|
res = re.sub("<#%s(.*?)>" % chid, "#%s" % name, res)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def _text_parse_links(text):
|
||||||
|
res = text
|
||||||
|
links = []
|
||||||
|
for link in re.findall("<(.*?)>", text):
|
||||||
|
split = link.split("|")
|
||||||
|
msg = split[1] + " " if len(split) > 1 else ""
|
||||||
|
res = re.sub("<(.*?)>", "%s[#####]" % msg, res)
|
||||||
|
links += [ split[0] ]
|
||||||
|
return (res, links)
|
||||||
|
|
||||||
def _text_parse_tags(text):
|
def _text_parse_tags(text):
|
||||||
text = _text_parse_uid(text)
|
text = _text_parse_uid(text)
|
||||||
text = _text_parse_channel(text)
|
text = _text_parse_channel(text)
|
||||||
return text
|
return _text_parse_links(text)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,10 +54,23 @@ class Message:
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
lines = []
|
lines = []
|
||||||
|
links = []
|
||||||
|
count = 0
|
||||||
for line in self.__text:
|
for line in self.__text:
|
||||||
line = _text_parse_tags(line)
|
line, link = _text_parse_tags(line)
|
||||||
|
while line.count("[#####]") > 0:
|
||||||
|
line = line.replace("[#####]", "[%s]" % count, 1)
|
||||||
|
count += 1
|
||||||
|
|
||||||
lines += [ "" ] + textwrap.wrap(line)
|
lines += [ "" ] + textwrap.wrap(line)
|
||||||
|
links += link
|
||||||
|
|
||||||
text = "\n ".join(lines)
|
text = "\n ".join(lines)
|
||||||
|
if len(links) > 0:
|
||||||
|
text += "\n __________"
|
||||||
|
for link in enumerate(links):
|
||||||
|
text += "\n [%s] %s" % (link[0], link[1])
|
||||||
|
|
||||||
time = self.__time.strftime("%I:%M:%S %p")
|
time = self.__time.strftime("%I:%M:%S %p")
|
||||||
return "\n%s | %s:\n%s\n" % (time, self.__user, text)
|
return "\n%s | %s:\n%s\n" % (time, self.__user, text)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue