Comparing version 2.0.0 to 2.0.2
@@ -0,1 +1,3 @@ | ||
const url = require('url'); | ||
const async = require('async'); | ||
@@ -200,5 +202,33 @@ const httpImageSize = require('http-image-size'); | ||
// Examples of what this will match: http://jsbin.com/eqocuh/552/edit | ||
exports.urlRegExp = /((?:(?:[A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+|(?:[A-Za-z0-9\.\-]+\.(?:com|org|net|gov|edu|co\.uk|io|horse|rodeo)))(?:(?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)(?:#?[\b\w\/!]+)(?:[\-\.\!\/\w]*))?)/g; | ||
exports.usernameRegExp = /(^|[^@\w])@(\w{1,15})\b/g; | ||
exports.usernameRegExp = /(^|[^@\w])@(\w{1,15})\b/g; | ||
exports.youTubeEmbedHtml = function(urlStr) { | ||
if (!urlStr) { | ||
return ''; | ||
} | ||
var uri = url.parse(urlStr, true); | ||
if (!uri) { | ||
return ''; | ||
} | ||
// http://stackoverflow.com/questions/2964678/jquery-youtube-url-validation-with-regex/10315969#10315969 | ||
var matches = uri.href.match(/https?:\/\/(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&(?:amp;)?v=))((\w|-){11})(?:\S+)?/); | ||
if (!matches || !matches[1]) { | ||
return ''; | ||
} | ||
var embedUrl = `https://www.youtube.com/embed/${matches[1]}?autohide=1&color=white&showinfo=0&theme=light`; | ||
if (uri.query.end) { | ||
embedUrl += `&end=${uri.query.end}`; | ||
} | ||
if (uri.query.start) { | ||
embedUrl += `&start=${uri.query.start}`; | ||
} | ||
return `<iframe allowfullscreen class="youtube" frameborder="0" src="${embedUrl}"></iframe>`; | ||
}; |
@@ -1,2 +0,2 @@ | ||
const url = require('url'); | ||
const mehdown = require('../index'); | ||
@@ -13,25 +13,9 @@ module.exports = function(md) { | ||
if (hrefIndex !== -1) { | ||
var uri = url.parse(token.attrs[hrefIndex][1], true); | ||
var embedHtml = mehdown.youTubeEmbedHtml(token.attrs[hrefIndex][1]); | ||
if (uri) { | ||
// http://stackoverflow.com/questions/2964678/jquery-youtube-url-validation-with-regex/10315969#10315969 | ||
var matches = uri.href.match(/https?:\/\/(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&(?:amp;)?v=))((\w|-){11})(?:\S+)?/); | ||
if (embedHtml) { | ||
tokens[idx + 1].content = ''; | ||
tokens[idx + 2].hidden = true; | ||
if (matches && matches[1]) { | ||
var id = matches[1]; | ||
var embedUrl = `https://www.youtube.com/embed/${id}?autohide=1&color=white&showinfo=0&theme=light`; | ||
if (uri.query.end) { | ||
embedUrl += `&end=${uri.query.end}`; | ||
} | ||
if (uri.query.start) { | ||
embedUrl += `&start=${uri.query.start}`; | ||
} | ||
tokens[idx + 1].content = ''; | ||
tokens[idx + 2].hidden = true; | ||
return `<iframe allowfullscreen class="youtube" frameborder="0" src="${embedUrl}"></iframe>`; | ||
} | ||
return embedHtml; | ||
} | ||
@@ -38,0 +22,0 @@ } |
@@ -20,3 +20,3 @@ { | ||
}, | ||
"version": "2.0.0" | ||
"version": "2.0.2" | ||
} |
@@ -271,1 +271,28 @@ const assert = require('assert'); | ||
}); | ||
describe('mehdown.youTubeEmbedHtml', function() { | ||
it('http://www.youtube.com/watch?v=kU9MuM4lP18', function() { | ||
var html = mehdown.youTubeEmbedHtml('http://www.youtube.com/watch?v=kU9MuM4lP18'); | ||
assert.equal(html, '<iframe allowfullscreen class="youtube" frameborder="0" src="https://www.youtube.com/embed/kU9MuM4lP18?autohide=1&color=white&showinfo=0&theme=light"></iframe>'); | ||
}); | ||
it('http://www.youtube.com/watch?feature=player_embedded&v=zIEIvi2MuEk', function() { | ||
var html = mehdown.youTubeEmbedHtml('http://www.youtube.com/watch?feature=player_embedded&v=zIEIvi2MuEk'); | ||
assert.equal(html, '<iframe allowfullscreen class="youtube" frameborder="0" src="https://www.youtube.com/embed/zIEIvi2MuEk?autohide=1&color=white&showinfo=0&theme=light"></iframe>'); | ||
}); | ||
it('`&` instead of `&` in URL', function() { | ||
var html = mehdown.youTubeEmbedHtml('http://www.youtube.com/watch?feature=player_embedded&v=zIEIvi2MuEk'); | ||
assert.equal(html, '<iframe allowfullscreen class="youtube" frameborder="0" src="https://www.youtube.com/embed/zIEIvi2MuEk?autohide=1&color=white&showinfo=0&theme=light"></iframe>'); | ||
}); | ||
it('http://www.youtube.com/watch?v=kU9MuM4lP18&start=10', function() { | ||
var html = mehdown.youTubeEmbedHtml('http://www.youtube.com/watch?v=kU9MuM4lP18&start=10'); | ||
assert.equal(html, '<iframe allowfullscreen class="youtube" frameborder="0" src="https://www.youtube.com/embed/kU9MuM4lP18?autohide=1&color=white&showinfo=0&theme=light&start=10"></iframe>'); | ||
}); | ||
it('http://www.youtube.com/watch?v=kU9MuM4lP18&start=10&end=20', function() { | ||
var html = mehdown.youTubeEmbedHtml('http://www.youtube.com/watch?v=kU9MuM4lP18&start=10&end=20'); | ||
assert.equal(html, '<iframe allowfullscreen class="youtube" frameborder="0" src="https://www.youtube.com/embed/kU9MuM4lP18?autohide=1&color=white&showinfo=0&theme=light&end=20&start=10"></iframe>'); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
80946
1149
1