Skip to content

Instantly share code, notes, and snippets.

@Quasimo
Created March 9, 2012 03:38
Show Gist options
  • Save Quasimo/2004885 to your computer and use it in GitHub Desktop.
Save Quasimo/2004885 to your computer and use it in GitHub Desktop.
# auto convert imgur.com links to image tags
def imgur(value):
imgs = re.findall('(http://imgur.com/[a-zA-Z0-9\/]+)\s?', value)
if (len(imgs) > 0):
for img in imgs:
img_id = re.findall('http://imgur.com/([a-zA-Z0-9\/]+)', img)
if (img_id[0] != ''):
value = value.replace('http://imgur.com/' + img_id[0], '<a href="http://imgur.com/' + img_id[0] + '" target="_blank"><img src="http://i.imgur.com/' + img_id[0] + '.jpg" class="imgly" border="0" /></a>')
return value
else:
return value
register.filter(imgur)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment