(function(module) {
	"use strict";

	var Youtube = {},
		embed = '<iframe class="youtube-plugin" width="640" height="360" src="//www.youtube.com/embed/$1?wmode=opaque" frameborder="0" allowfullscreen></iframe>';

	Youtube.parse = function(postContent, callback) {
		// modified from http://stackoverflow.com/questions/7168987/
		var	regularUrl = /<a href="(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)">.+<\/a>/g,
			embedUrl = /<a href="(?:https?:\/\/)?(?:www\.)youtube.com\/embed\/([\w\-_]+)">.+<\/a>/;

		if (postContent.match(embedUrl)) {
			postContent = postContent.replace(embedUrl, embed);
		} else if (postContent.match(regularUrl)) {
			postContent = postContent.replace(regularUrl, embed);
		}

		callback(null, postContent);
	};

	module.exports = Youtube;
}(module));

(function(module) {
	"use strict";

	var Youtube = {},
		embed = '<iframe class="youtube-plugin" width="640" height="360" src="//www.youtube.com/embed/$1?wmode=opaque" frameborder="0" allowfullscreen></iframe>';

	Youtube.parse = function(postContent, callback) {
		// modified from http://stackoverflow.com/questions/7168987/
		var	regularUrl = /<a href="(?:https?:\/\/)?(?:www\.)?(?:youtube\.com)\/(?:watch\?v=)(.+)">.+<\/a>/g;
		var	shortUrl = /<a href="(?:https?:\/\/)?(?:www\.)?(?:youtu\.be)\/(.+)">.+<\/a>/g;
		var	embedUrl = /<a href="(?:https?:\/\/)?(?:www\.)youtube.com\/embed\/([\w\-_]+)">.+<\/a>/;

		if (postContent.match(embedUrl)) {
			postContent = postContent.replace(embedUrl, embed);
		}
		if (postContent.match(regularUrl)) {
			postContent = postContent.replace(regularUrl, embed);
		}
		if (postContent.match(shortUrl)) {
			postContent = postContent.replace(shortUrl, embed);
		}

		callback(null, postContent);
	};

	module.exports = Youtube;
}(module));

Fix plugin converting user links to videos
Fix plugin converting user links to videos

An issue in the regex intentionally placed for the simultaneous parsing of youtu
be.com/watch?v= and youtu.be/ links caused links in the format youtube.com/user/
somebody and youtube.com/somebody to wrongly show up as videos. This made going
to the links impossible. This commit separates the shortUrl into its own regex t
o be matched separately, so the regular URL does not have false positives.
