Skip to content
This repository has been archived by the owner on Apr 15, 2018. It is now read-only.

Commit

Permalink
fix on embed links
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed May 15, 2013
1 parent 343da8c commit 3ca7992
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions june/markdown.py
Expand Up @@ -9,40 +9,56 @@ def autolink(self, link, is_email):
title = link.replace('http://', '').replace('https://', '')

#: youtube.com
pattern = r'http://www.youtube.com/watch\?v=([a-zA-Z0-9\-\_]+)'
pattern = r'http://www\.youtube\.com\/watch\?v=([a-zA-Z0-9\-\_]+)'
match = re.match(pattern, link)
if not match:
pattern = r'http://youtu.be/([a-zA-Z0-9\-\_]+)'
pattern = r'http:\/\/youtu.be\/([a-zA-Z0-9\-\_]+)'
match = re.match(pattern, link)
if match:
value = ('<iframe width="560" height="315" src='
'"http://www.youtube.com/embed/%(id)s" '
'frameborder="0" allowfullscreen></iframe>'
'<div><a rel="nofollow" href="%(link)s">'
'%(title)s</a></div>'
) % {'id': match.group(1), 'link': link, 'title': title}
value = (
'<iframe width="560" height="315" src='
'"http://www.youtube.com/embed/%(id)s" '
'frameborder="0" allowfullscreen></iframe>'
'<div><a rel="nofollow" href="%(link)s">'
'%(title)s</a></div>'
) % {'id': match.group(1), 'link': link, 'title': title}
return value

#: gist support
pattern = r'(https?://gist.github.com/[\d]+)'
pattern = r'(https?:\/\/gist\.github\.com\/.+\d+)'
match = re.match(pattern, link)
if match:
value = ('<script src="%(link)s.js"></script>'
'<div><a rel="nofollow" href="%(link)s">'
'%(title)s</a></div>'
) % {'link': match.group(1), 'title': title}
value = (
'<script src="%(link)s.js"></script>'
'<div><a rel="nofollow" href="%(link)s">'
'%(title)s</a></div>'
) % {'link': match.group(1), 'title': title}
return value

#: vimeo.com
pattern = r'http://vimeo.com/([\d]+)'
pattern = r'https?:\/\/vimeo\.com\/([\d]+)'
match = re.match(pattern, link)
if match:
value = ('<iframe width="500" height="281" frameborder="0" '
'src="http://player.vimeo.com/video/%(id)s" '
'allowFullScreen></iframe>'
'<div><a rel="nofollow" href="%(link)s">'
'%(title)s</a></div>'
) % {'id': match.group(1), 'link': link, 'title': title}
value = (
'<iframe width="566" height="318" frameborder="0" '
'src="https://player.vimeo.com/video/%(id)s" '
'allowFullScreen></iframe>'
'<div><a rel="nofollow" href="%(link)s">'
'%(title)s</a></div>'
) % {'id': match.group(1), 'link': link, 'title': title}
return value

#: ascii.io
pattern = r'(http:\/\/ascii\.io\/a\/\d+)'
match = re.match(pattern, link)
if match:
value = (
'<iframe width="566" height="600" frameborder="0" '
'src="%(url)s/raw" '
'allowFullScreen></iframe>'
'<div><a rel="nofollow" href="%(link)s">'
'%(title)s</a></div>'
) % {'url': match.group(1), 'link': link, 'title': title}
return value

if is_email:
Expand Down

0 comments on commit 3ca7992

Please sign in to comment.