newline.js 601 Bytes
/**
 * Showdown extension for GFM newlines.
 * 
 * In very clear cases, let newlines become <br/> tags.
 *
 * This implementation is adopted from showdown-ghost.
 *
 */
(function () {
	function newline() {
		return [{
			type: 'lang',
			filter: function(text) {
				return text.replace(/^( *(\d+\.  {1,4}|[\w\<\'\">\-*+])[^\n]*)\n{1}(?!\n| *\d+\. {1,4}| *[-*+] +|#|$)/gm, function(e) {
					return e.trim() + "  \n";
				})
			}
		}];
	}

	if (window && window.showdown) {
		window.showdown.extensions.newline = newline;
	}

	if (typeof module !== 'undefined') {
		module.exports = newline;
	}
})();