diff --git a/packages/format-library/src/code/index.js b/packages/format-library/src/code/index.js index f3651504d57ce8..27a99ebc989e21 100644 --- a/packages/format-library/src/code/index.js +++ b/packages/format-library/src/code/index.js @@ -20,16 +20,18 @@ export const code = { __unstableInputRule( value ) { const BACKTICK = '`'; const { start, text } = value; - const characterBefore = text.slice( start - 1, start ); + const characterBefore = text[ start - 1 ]; // Quick check the text for the necessary character. if ( characterBefore !== BACKTICK ) { return value; } - const textBefore = text.slice( 0, start - 1 ); - const indexBefore = textBefore.lastIndexOf( BACKTICK ); + if ( start - 2 < 0 ) { + return value; + } + const indexBefore = text.lastIndexOf( BACKTICK, start - 2 ); if ( indexBefore === -1 ) { return value; }