Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mehdown

Package Overview
Dependencies
Maintainers
2
Versions
134
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mehdown - npm Package Compare versions

Comparing version 2.0.0 to 2.0.2

36

lib/index.js

@@ -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>`;
};

28

lib/plugins/youtube.js

@@ -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('`&amp;` instead of `&` in URL', function() {
var html = mehdown.youTubeEmbedHtml('http://www.youtube.com/watch?feature=player_embedded&amp;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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc