Beispiel #1
0
 def __call__(self, s, enable_topic=False):
     self.enable_topic = enable_topic
     ret = {}
     r = ''
     pos = []
     b = 0
     e = 0
     for i in MENTION_RE.finditer(s):
         b, e1 = i.span()
         r += html_quote(s[e:b])
         id, replaced, kind = self.repl(i)
         if id and kind:
             pos.append((b, e1, id, kind))
         r += replaced
         e = e1
     r += html_quote(s[e:])
     ret['origin'] = s
     ret['postions'] = pos
     ret['html'] = covert_space_and_newline(r)
     return ret
Beispiel #2
0
 def repl(self, match):
     at, name, protocol, link, topic = match.groups()
     #print 'repl enable_topic=', self.enable_topic
     #print 'mention', at, name, protocol, link, topic
     if at and name:
         user_id = self.users_dict.get(name.lower(), None)
         card = user_id and Card.get(user_id)
         if card:
             return user_id, '<a href="%s">@%s</a>' % (card.path, card.screen_name), 'card'
     if protocol and link:
         url = protocol + link
         if url.startswith(SITE):
             return None, '<a href="%s">%s</a>' % (url, url), 'url'
         else:
             return None, '<a href="%s" target="_blank">%s</a>' % (url, url), 'url'
     if self.enable_topic and topic:
         return topic, '<a href="/topic/%s">#%s#</a>' % (html_quote(topic.upper()), html_quote(topic.upper())), 'topic'
     return None, at or topic, None
Beispiel #3
0
 def setInnerText(self, text):
     self._inner_html = html_quote(text)
Beispiel #4
0
 def setInnerText(self, text):
     self.setInnerHTML(html_quote(text))
Beispiel #5
0
 def html_entry(entry):
     d = dict(entry.__dict__)
     d["args"] = "".join([html_entry_args_template % html_quote(a) for a in entry.args])
     d["description"] = html_quote(" ".join(entry.description))
     return html_entry_template % d
Beispiel #6
0
 def setInnerText(self, text):
     self._inner_html = html_quote(text)
Beispiel #7
0
 def setInnerText(self, text):
     self.setInnerHTML(html_quote(text))
Beispiel #8
0
 def url(self):
     return '%s/topic/%s' % (SITE, html_quote(self.name))
Beispiel #9
0
 def path(self):
     return '/topic/%s' % html_quote(self.name)
Beispiel #10
0
 def html_entry(entry):
     d = dict(entry.__dict__)
     d["args"] = "".join(
         [html_entry_args_template % html_quote(a) for a in entry.args])
     d["description"] = html_quote(" ".join(entry.description))
     return html_entry_template % d