bugdown: Use named match for Gravatar email

(imported from commit 778c4b6d754f975c89a91336593d2f62e49249d5)
This commit is contained in:
Keegan McAllister 2012-10-21 20:15:44 -04:00
parent ae7c4b302b
commit d72aea25f2
1 changed files with 2 additions and 4 deletions

View File

@ -6,12 +6,10 @@ from zephyr.lib.bugdown import codehilite
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)),))
% (gravatar_hash(match.group('email')),))
return img
class Bugdown(markdown.Extension):
@ -21,7 +19,7 @@ class Bugdown(markdown.Extension):
del md.parser.blockprocessors['hashheader']
del md.parser.blockprocessors['setextheader']
md.inlinePatterns.add('gravatar', Gravatar(r'!gravatar\(([^)]*)\)'), '_begin')
md.inlinePatterns.add('gravatar', Gravatar(r'!gravatar\((?P<email>[^)]*)\)'), '_begin')
# We need to re-initialize the markdown engine every 30 messages
# due to some sort of performance leak in the markdown library.