fix: remove string.repeat for ie11 (#1772)
This commit is contained in:
parent
7183d4fee9
commit
27070705d3
@ -1,6 +1,7 @@
|
||||
const Tokenizer = require('./Tokenizer.js');
|
||||
const { defaults } = require('./defaults.js');
|
||||
const { block, inline } = require('./rules.js');
|
||||
const { repeatString } = require('./helpers.js');
|
||||
|
||||
/**
|
||||
* smartypants text replacement
|
||||
@ -340,14 +341,14 @@ module.exports = class Lexer {
|
||||
if (links.length > 0) {
|
||||
while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
|
||||
if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Mask out other blocks
|
||||
while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
||||
}
|
||||
|
||||
while (src) {
|
||||
|
@ -228,6 +228,22 @@ function checkSanitizeDeprecation(opt) {
|
||||
}
|
||||
}
|
||||
|
||||
// copied from https://stackoverflow.com/a/5450113/806777
|
||||
function repeatString(pattern, count) {
|
||||
if (count < 1) {
|
||||
return '';
|
||||
}
|
||||
let result = '';
|
||||
while (count > 1) {
|
||||
if (count & 1) {
|
||||
result += pattern;
|
||||
}
|
||||
count >>= 1;
|
||||
pattern += pattern;
|
||||
}
|
||||
return result + pattern;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
escape,
|
||||
unescape,
|
||||
@ -239,5 +255,6 @@ module.exports = {
|
||||
splitCells,
|
||||
rtrim,
|
||||
findClosingBracket,
|
||||
checkSanitizeDeprecation
|
||||
checkSanitizeDeprecation,
|
||||
repeatString
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user