Skip to content

Instantly share code, notes, and snippets.

@alexkravets
Created May 22, 2013 05:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexkravets/5625532 to your computer and use it in GitHub Desktop.
Save alexkravets/5625532 to your computer and use it in GitHub Desktop.
Showdown extension for Youtube videos
#
# 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