File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 11const Tokenizer = require ( './Tokenizer.js' ) ;
22const { defaults } = require ( './defaults.js' ) ;
33const { block, inline } = require ( './rules.js' ) ;
4+ const { repeatString } = require ( './helpers.js' ) ;
45
56/**
67 * smartypants text replacement
@@ -340,14 +341,14 @@ module.exports = class Lexer {
340341 if ( links . length > 0 ) {
341342 while ( ( match = this . tokenizer . rules . inline . reflinkSearch . exec ( maskedSrc ) ) != null ) {
342343 if ( links . includes ( match [ 0 ] . slice ( match [ 0 ] . lastIndexOf ( '[' ) + 1 , - 1 ) ) ) {
343- maskedSrc = maskedSrc . slice ( 0 , match . index ) + '[' + 'a' . repeat ( match [ 0 ] . length - 2 ) + ']' + maskedSrc . slice ( this . tokenizer . rules . inline . reflinkSearch . lastIndex ) ;
344+ maskedSrc = maskedSrc . slice ( 0 , match . index ) + '[' + repeatString ( 'a' , match [ 0 ] . length - 2 ) + ']' + maskedSrc . slice ( this . tokenizer . rules . inline . reflinkSearch . lastIndex ) ;
344345 }
345346 }
346347 }
347348 }
348349 // Mask out other blocks
349350 while ( ( match = this . tokenizer . rules . inline . blockSkip . exec ( maskedSrc ) ) != null ) {
350- maskedSrc = maskedSrc . slice ( 0 , match . index ) + '[' + 'a' . repeat ( match [ 0 ] . length - 2 ) + ']' + maskedSrc . slice ( this . tokenizer . rules . inline . blockSkip . lastIndex ) ;
351+ maskedSrc = maskedSrc . slice ( 0 , match . index ) + '[' + repeatString ( 'a' , match [ 0 ] . length - 2 ) + ']' + maskedSrc . slice ( this . tokenizer . rules . inline . blockSkip . lastIndex ) ;
351352 }
352353
353354 while ( src ) {
Original file line number Diff line number Diff line change @@ -228,6 +228,22 @@ function checkSanitizeDeprecation(opt) {
228228 }
229229}
230230
231+ // copied from https://stackoverflow.com/a/5450113/806777
232+ function repeatString ( pattern , count ) {
233+ if ( count < 1 ) {
234+ return '' ;
235+ }
236+ let result = '' ;
237+ while ( count > 1 ) {
238+ if ( count & 1 ) {
239+ result += pattern ;
240+ }
241+ count >>= 1 ;
242+ pattern += pattern ;
243+ }
244+ return result + pattern ;
245+ }
246+
231247module . exports = {
232248 escape,
233249 unescape,
@@ -239,5 +255,6 @@ module.exports = {
239255 splitCells,
240256 rtrim,
241257 findClosingBracket,
242- checkSanitizeDeprecation
258+ checkSanitizeDeprecation,
259+ repeatString
243260} ;
You can’t perform that action at this time.
0 commit comments