From c31462c2782a33886e737cf33424a36a95c81f97 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Tue, 16 Oct 2012 22:42:19 -0400 Subject: [PATCH] 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) --- zephyr/lib/bugdown.py | 14 ++++++++++++++ zephyr/static/styles/zephyr.css | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/zephyr/lib/bugdown.py b/zephyr/lib/bugdown.py index f06283cebf..b9b39e81ed 100644 --- a/zephyr/lib/bugdown.py +++ b/zephyr/lib/bugdown.py @@ -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 diff --git a/zephyr/static/styles/zephyr.css b/zephyr/static/styles/zephyr.css index 2b8d2eee24..20be33c355 100644 --- a/zephyr/static/styles/zephyr.css +++ b/zephyr/static/styles/zephyr.css @@ -415,3 +415,7 @@ table.floating_recipient { margin-top: 0px; margin-bottom: 0px; } + +.message_body_gravatar { + margin-bottom: 2px; +}