1. Josh VanderLinden
  2. twibber

Commits

Josh VanderLinden  committed b49b570

Made it so the plaintext version of the tweet would have some ampersand love too.

  • Participants
  • Parent commits 0dde46c
  • Branches default

Comments (0)

Files changed (1)

File core.py

View file
 
 AT_REPLY_RE = re.compile('@(\w+)')
 HASH_TAG_RE = re.compile('(?<!&)#([\w\-]+)')
+AMP_RE = re.compile('&(?!#?\w+;)')
 HREF_RE = re.compile('(http://([\w+?\.\w+]+)([a-z0-9\~\!\@\#\$\%\^\&amp;\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*))', re.I)
 HREF_TEMPLATE = '<strong><a href="http://twitter.com/%(user)s/status/%(id)i">%(user)s</a></strong>'
 
         log.debug('HTML Text: ' + text)
 
         pre = '[ %i ] %s%s' % (cache.get_id(tweet.id), t_type, prefix)
-        plaintext = tweet.text.replace('&', '&amp;')
+        plaintext = AMP_RE.sub('&amp;', tweet.text)
         params = {
             'body': pre + name + ': ' + self.ShowLinkDestinations(plaintext),
             'html': pre + text
         else:
             uhref = ''
 
-        #text = clean(tweet.text.replace('& ', '&amp; '))
         text = self.ShowLinkDestinations(tweet.text)
         at_users = AT_REPLY_RE.findall(text)
         template = '<span%(c)s>@<a href="http://twitter.com/%(u)s"%(c)s>%(u)s</a></span>'
         text = clean(text)
 
         # take care of any lingering ampersands
-        text = re.sub('&(?!#?\w+;)', '&amp;', text)
+        text = AMP_RE.sub('&amp;', text)
 
         return uhref + ': ' + text