Skip to content

Commit ddd1740

Browse files
committed
Fixed remarkable-regex not support IE, and use counter instead of random on id to avoid collision
1 parent db324c5 commit ddd1740

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

public/vendor/remarkable-regex.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,28 @@ stuff.escape = function(html) {
1919
.replace(/>/g, '>')
2020
}
2121

22+
Object.setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
23+
if (!isIE9()) {
24+
obj.__proto__ = proto;
25+
} else {
26+
/** IE9 fix - copy object methods from the protype to the new object **/
27+
for (var prop in proto) {
28+
obj[prop] = proto[prop];
29+
}
30+
}
31+
32+
return obj;
33+
};
34+
35+
var isIE9 = function() {
36+
return navigator.appVersion.indexOf("MSIE") > 0;
37+
};
38+
39+
/**
40+
* Counter for multi usage.
41+
*/
42+
var counter = 0
43+
2244
/**
2345
* Constructor function
2446
*/
@@ -30,10 +52,10 @@ function Plugin(regexp, replacer) {
3052
self.options = options
3153
self.init(remarkable)
3254
}
33-
55+
3456
// initialize plugin object
35-
self.__proto__ = Plugin.prototype
36-
57+
Object.setPrototypeOf(self, Plugin.prototype)
58+
3759
// clone regexp with all the flags
3860
var flags = (regexp.global ? 'g' : '')
3961
+ (regexp.multiline ? 'm' : '')
@@ -43,10 +65,11 @@ function Plugin(regexp, replacer) {
4365

4466
// copy init options
4567
self.replacer = replacer
46-
68+
4769
// this plugin can be inserted multiple times,
4870
// so we're generating unique name for it
49-
self.id = 'regexp-' + JSON.stringify(Math.random()).slice(2)
71+
self.id = 'regexp-' + counter
72+
counter++
5073

5174
return self
5275
}

0 commit comments

Comments
 (0)