Allow users to embed Gravatars in messages

We'll use this internally for the commit bot.  We might eventually disable it
for external users.

(imported from commit 3136cd9faadc6b81355889d2ee6472985da87fbe)
This commit is contained in:
Keegan McAllister 2012-10-16 22:42:19 -04:00
parent 81f0d61c3b
commit c31462c278
2 changed files with 18 additions and 0 deletions

View File

@ -1,6 +1,18 @@
import re
import markdown
from zephyr.lib.avatar import gravatar_hash
class Gravatar(markdown.inlinepatterns.Pattern):
def handleMatch(self, match):
# NB: the first match of our regex is match.group(2) due to
# markdown internal matches
img = markdown.util.etree.Element('img')
img.set('class', 'message_body_gravatar img-rounded')
img.set('src', 'https://secure.gravatar.com/avatar/%s?d=identicon&s=30'
% (gravatar_hash(match.group(2)),))
return img
class Bugdown(markdown.Extension):
def extendMarkdown(self, md, md_globals):
del md.inlinePatterns['image_link']
@ -8,6 +20,8 @@ class Bugdown(markdown.Extension):
del md.parser.blockprocessors['hashheader']
del md.parser.blockprocessors['setextheader']
md.inlinePatterns.add('gravatar', Gravatar(r'!gravatar\(([^)]*)\)'), '_begin')
# We need to re-initialize the markdown engine every 30 messages
# due to some sort of performance leak in the markdown library.
MAX_MD_ENGINE_USES = 30

View File

@ -415,3 +415,7 @@ table.floating_recipient {
margin-top: 0px;
margin-bottom: 0px;
}
.message_body_gravatar {
margin-bottom: 2px;
}