Make html_for_tweet() link a replied-to username

If a tweet was a reply, then when `html_for_tweet()` tried to turn
the initial "@username" into a link, there was:

    > NameError: name 'sub_expr' is not defined

This is now fixed, with a test to ensure the "@username" becomes
a link.
This commit is contained in:
Phil Gyford 2017-10-03 19:12:02 +01:00
parent 97f78fd89b
commit 0ee9b76b5c
3 changed files with 13 additions and 2 deletions

View file

@ -578,6 +578,9 @@ class Twython(EndpointsMixin, object):
temp['replacement'] = mention_html
entities.append(temp)
else:
# Make the '@username' at the start, before
# display_text, into a link:
sub_expr = r'(?<!>)' + orig_tweet_text[temp['start']:temp['end']] + '(?!</a>)'
prefix_text = re.sub(sub_expr, mention_html, prefix_text)
# Hashtags