Skip to content

Commit a45e528

Browse files
committed
remove string format function from global object
1 parent 9875da0 commit a45e528

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

dist/highlightjs-line-numbers.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/highlightjs-line-numbers.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
NUMBER_LINE_NAME = 'hljs-ln-n',
99
DATA_ATTR_NAME = 'data-line-number';
1010

11+
// string format
1112
// https://wcoder.github.io/notes/string-format-for-string-formating-in-javascript
12-
String.prototype.format = String.prototype.f = function () {
13-
var args = arguments;
14-
return this.replace(/\{(\d+)\}/g, function(m, n){
13+
var format = function (str, args) {
14+
return str.replace(/\{(\d+)\}/g, function(m, n){
1515
return args[n] ? args[n] : m;
1616
});
1717
};
@@ -28,15 +28,15 @@
2828
function addStyles () {
2929
var css = document.createElement('style');
3030
css.type = 'text/css';
31-
css.innerHTML = (
31+
css.innerHTML = format(
3232
'.{0}{border-collapse:collapse}\
3333
.{0} td{padding:0}\
34-
.{1}:before{content:attr({2})}'
35-
).format(
34+
.{1}:before{content:attr({2})}',
35+
[
3636
TABLE_NAME,
3737
NUMBER_LINE_NAME,
3838
DATA_ATTR_NAME
39-
);
39+
]);
4040
document.getElementsByTagName('head')[0].appendChild(css);
4141
}
4242

@@ -81,27 +81,27 @@
8181
var html = '';
8282

8383
for (var i = 0, l = lines.length; i < l; i++) {
84-
html += (
84+
html += format(
8585
'<tr>\
8686
<td class="{0}">\
8787
<div class="{1} {2}" {3}="{5}"></div>\
8888
</td>\
8989
<td class="{4}">\
9090
<div class="{1}">{6}</div>\
9191
</td>\
92-
</tr>'
93-
).format(
92+
</tr>',
93+
[
9494
NUMBERS_BLOCK_NAME,
9595
LINE_NAME,
9696
NUMBER_LINE_NAME,
9797
DATA_ATTR_NAME,
9898
CODE_BLOCK_NAME,
9999
i + 1,
100100
lines[i].length > 0 ? lines[i] : ' '
101-
);
101+
]);
102102
}
103103

104-
element.innerHTML = '<table class="{0}">{1}</table>'.format(TABLE_NAME, html);
104+
element.innerHTML = format('<table class="{0}">{1}</table>', [ TABLE_NAME, html ]);
105105
}
106106
}
107107

0 commit comments

Comments
 (0)