Skip to content

Commit

Permalink
integrate github improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
anandology committed Dec 28, 2009
1 parent aedd020 commit 570fc50
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions showdown.js
Expand Up @@ -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 "<a href='" + wholeMatch + "'>" + wholeMatch + "</a>";
});
text = text.replace(/[a-z0-9_\-+=.]+@[a-z0-9\-]+(\.[a-z0-9-]+)+/ig, function(wholeMatch){
return "<a href='mailto:" + wholeMatch + "'>" + wholeMatch + "</a>";
});


return text;
}

Expand Down Expand Up @@ -351,8 +363,8 @@ var _RunBlockGamut = function(text) {
// Do Horizontal Rules:
var key = hashBlock("<hr />");
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);
Expand Down Expand Up @@ -978,9 +990,11 @@ var _EncodeCode = function(text) {
var _DoItalicsAndBold = function(text) {

// <strong> must go first:
text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[\*_]*)\1/g,
text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g,
"<strong>$2</strong>");

text = text.replace(/(\w)_(\w)/g, "$1~E95E$2") // ** GFM ** "~E95E" == escaped "_"

text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g,
"<em>$2</em>");

Expand Down Expand Up @@ -1062,6 +1076,7 @@ var _FormParagraphs = function(text) {
}
else if (str.search(/\S/) >= 0) {
str = _RunSpanGamut(str);
str = str.replace(/\n/g,"<br />"); // ** GFM **
str = str.replace(/^([ \t]*)/g,"<p>");
str += "</p>"
grafsOut.push(str);
Expand Down Expand Up @@ -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");
}
}

0 comments on commit 570fc50

Please sign in to comment.