From 570fc50b55c81af9114676796b2dfa098d869b84 Mon Sep 17 00:00:00 2001 From: Anand Chitipothu Date: Mon, 28 Dec 2009 15:46:49 +0530 Subject: [PATCH] integrate github improvements source: http://github.com/github/github-flavored-markdown --- showdown.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/showdown.js b/showdown.js index 0efa6c5..ab3377e 100644 --- a/showdown.js +++ b/showdown.js @@ -149,6 +149,18 @@ this.makeHtml = function(text) { // attacklab: Restore tildes text = text.replace(/~T/g,"~"); + // ** GFM ** Auto-link URLs and emails + text = text.replace(/https?\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!]/g, function(wholeMatch){ + var left = RegExp.leftContext + var right = RegExp.rightContext + if (left.match(/<[^>]+$/) && right.match(/^[^>]*>/)) {return wholeMatch} + return "" + wholeMatch + ""; + }); + text = text.replace(/[a-z0-9_\-+=.]+@[a-z0-9\-]+(\.[a-z0-9-]+)+/ig, function(wholeMatch){ + return "" + wholeMatch + ""; + }); + + return text; } @@ -351,8 +363,8 @@ var _RunBlockGamut = function(text) { // Do Horizontal Rules: var key = hashBlock("
"); text = text.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm,key); - text = text.replace(/^[ ]{0,2}([ ]?-[ ]?){3,}[ \t]*$/gm,key); - text = text.replace(/^[ ]{0,2}([ ]?_[ ]?){3,}[ \t]*$/gm,key); + text = text.replace(/^[ ]{0,2}([ ]?\-[ ]?){3,}[ \t]*$/gm,key); + text = text.replace(/^[ ]{0,2}([ ]?\_[ ]?){3,}[ \t]*$/gm,key); text = _DoLists(text); text = _DoCodeBlocks(text); @@ -978,9 +990,11 @@ var _EncodeCode = function(text) { var _DoItalicsAndBold = function(text) { // must go first: - text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[\*_]*)\1/g, + text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g, "$2"); + text = text.replace(/(\w)_(\w)/g, "$1~E95E$2") // ** GFM ** "~E95E" == escaped "_" + text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g, "$2"); @@ -1062,6 +1076,7 @@ var _FormParagraphs = function(text) { } else if (str.search(/\S/) >= 0) { str = _RunSpanGamut(str); + str = str.replace(/\n/g,"
"); // ** GFM ** str = str.replace(/^([ \t]*)/g,"

"); str += "

" grafsOut.push(str); @@ -1303,4 +1318,4 @@ var Showdown = Attacklab.showdown; // If anyone's interested, tell the world that this file's been loaded if (Attacklab.fileLoaded) { Attacklab.fileLoaded("showdown.js"); -} \ No newline at end of file +}