Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbr/474471 to your computer and use it in GitHub Desktop.
Save jbr/474471 to your computer and use it in GitHub Desktop.
From e22317131b97d0faa5510b528ef515ccbbbd3e8e Mon Sep 17 00:00:00 2001
From: Jacob Rothstein <github@jacobrothstein.com>
Date: Tue, 13 Jul 2010 13:24:34 -0700
Subject: [PATCH] fix showdown to work in chrome (don't use RegExp.leftContext and RegExp.rightContext globals)
---
scripts/showdown.js | 10 ++++------
1 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/scripts/showdown.js b/scripts/showdown.js
index e8772af..582a40f 100644
--- a/scripts/showdown.js
+++ b/scripts/showdown.js
@@ -188,20 +188,18 @@ this.makeHtml = function(text) {
});
// ** GFM ** Auto-link #issue if GitHub.nameWithOwner is defined
- text = text.replace(/#([0-9]+)/ig, function(wholeMatch,issue){
+ text = text.replace(/#([0-9]+)/ig, function(wholeMatch,issue,matchIndex){
if (typeof(GitHub) == "undefined" || typeof(GitHub.nameWithOwner) == "undefined") {return wholeMatch;}
- var left = RegExp.leftContext
- var right = RegExp.rightContext
+ var left = text.slice(0, matchIndex), right = text.slice(matchIndex)
if (left == "" || left.match(/[a-z0-9_\-+=.]$/) || (left.match(/<[^>]+$/) && right.match(/^[^>]*>/))) {return wholeMatch;}
return "<a href='http://github.com/" + GitHub.nameWithOwner + "/issues/#issue/" + issue + "'>" + wholeMatch + "</a>";
});
// ** GFM ** Auto-link user#issue if GitHub.nameWithOwner is defined
- text = text.replace(/([a-z0-9_\-+=.]+)#([0-9]+)/ig, function(wholeMatch,username,issue){
+ text = text.replace(/([a-z0-9_\-+=.]+)#([0-9]+)/ig, function(wholeMatch,username,issue,matchIndex){
if (typeof(GitHub) == "undefined" || typeof(GitHub.nameWithOwner) == "undefined") {return wholeMatch;}
GitHub.repoName = GitHub.repoName || _GetRepoName()
- var left = RegExp.leftContext
- var right = RegExp.rightContext
+ var left = text.slice(0, matchIndex), right = text.slice(matchIndex)
if (left.match(/\/$/) || (left.match(/<[^>]+$/) && right.match(/^[^>]*>/))) {return wholeMatch;}
return "<a href='http://github.com/" + username + "/" + GitHub.repoName + "/issues/#issue/" + issue + "'>" + wholeMatch + "</a>";
});
--
1.7.1
@hsribei
Copy link

hsribei commented Oct 11, 2010

Thank you for this. Saved my life :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment