Created
May 22, 2013 05:55
-
-
Save alexkravets/5625532 to your computer and use it in GitHub Desktop.
Showdown extension for Youtube videos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Youtube iFrame Extension | |
# | |
window.Showdown.extensions.video = (converter) -> | |
[ | |
{ | |
type : 'lang', | |
regex : '\\^\\^([\\S]+)', | |
replace : (match, url) -> | |
youtube = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/ | |
if youtube.test(url) | |
m = url.match(youtube) | |
if m and m[7].length == 11 | |
video_id = m[7] | |
"""<iframe src="http://www.youtube.com/embed/#{video_id}?rel=0" | |
frameborder="0" allowfullscreen></iframe>""" | |
else | |
match | |
else | |
match | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment