@@ -2960,20 +2960,28 @@ class CodeFriendly(ItalicAndBoldProcessor):
29602960    ''' 
29612961    name  =  'code-friendly' 
29622962
2963+     def  __init__ (self , md , options ):
2964+         super ().__init__ (md , options )
2965+ 
2966+         # add a prefix to it so we don't interfere with escaped/hashed chars from other stages 
2967+         self .hash_table [_hash_text (self .name  +  '_' )] =  '_' 
2968+         self .hash_table [_hash_text (self .name  +  '__' )] =  '__' 
2969+ 
29632970    def  sub (self , match : re .Match ) ->  str :
29642971        syntax  =  match .group (1 )
29652972        text : str  =  match .string [match .start (): match .end ()]
29662973        if  '_'  in  syntax :
2967-             # if using _this_ syntax, hash the whole thing so that it doesn't get processed 
2968-             key  =  _hash_text (text )
2969-             self .hash_table [key ] =  text 
2970-             return  key 
2974+             # if using _this_ syntax, hash it to avoid processing, but don't hash the contents incase of nested syntax 
2975+             text  =  text .replace (syntax , _hash_text (self .name  +  syntax ))
2976+             return  text 
29712977        elif  '_'  in  text :
2972-             # if the text within the bold/em markers contains '_' then hash those contents to protect them from em_re 
2973-             text  =  text [len (syntax ): - len (syntax )]
2974-             key  =  _hash_text (text )
2975-             self .hash_table [key ] =  text 
2976-             return  syntax  +  key  +  syntax 
2978+             # if the text within the bold/em markers contains '_' then hash those chars to protect them from em_re 
2979+             text  =  (
2980+                 text [len (syntax ): - len (syntax )]
2981+                 .replace ('__' , _hash_text (self .name  +  '__' ))
2982+                 .replace ('_' , _hash_text (self .name  +  '_' ))
2983+             )
2984+             return  syntax  +  text  +  syntax 
29772985        # if no underscores are present, the text is fine and we can just leave it alone 
29782986        return  super ().sub (match )
29792987
0 commit comments