@@ -5,6 +5,12 @@ export const isInsideCodeBlock = (text: string, position: number): boolean => {
55 let inMultilineCode = false ;
66
77 for ( let i = 0 ; i < position ; i += 1 ) {
8+ // Skip escaped backticks
9+ if ( text [ i ] === "\\" && i + 1 < text . length && text [ i + 1 ] === "`" ) {
10+ i += 1 ;
11+ continue ;
12+ }
13+
814 // Check for triple backticks (multiline code blocks)
915 if ( text . substring ( i , i + 3 ) === "```" ) {
1016 inMultilineCode = ! inMultilineCode ;
@@ -30,10 +36,15 @@ export const isPartOfTripleBacktick = (text: string, i: number): boolean => {
3036 return isTripleStart || isTripleMiddle || isTripleEnd ;
3137} ;
3238
33- // Counts single backticks that are not part of triple backticks
39+ // Counts single backticks that are not part of triple backticks or escaped
3440export const countSingleBackticks = ( text : string ) : number => {
3541 let count = 0 ;
3642 for ( let i = 0 ; i < text . length ; i += 1 ) {
43+ // Skip escaped backticks
44+ if ( text [ i ] === "\\" && i + 1 < text . length && text [ i + 1 ] === "`" ) {
45+ i += 1 ;
46+ continue ;
47+ }
3748 if ( text [ i ] === "`" && ! isPartOfTripleBacktick ( text , i ) ) {
3849 count += 1 ;
3950 }
@@ -52,6 +63,12 @@ export const isWithinCompleteInlineCode = (
5263 let inlineCodeStart = - 1 ;
5364
5465 for ( let i = 0 ; i < text . length ; i += 1 ) {
66+ // Skip escaped backticks
67+ if ( text [ i ] === "\\" && i + 1 < text . length && text [ i + 1 ] === "`" ) {
68+ i += 1 ;
69+ continue ;
70+ }
71+
5572 // Check for triple backticks (multiline code blocks)
5673 if ( text . substring ( i , i + 3 ) === "```" ) {
5774 inMultilineCode = ! inMultilineCode ;
0 commit comments