@@ -2960,20 +2960,28 @@ class CodeFriendly(ItalicAndBoldProcessor):
2960
2960
'''
2961
2961
name = 'code-friendly'
2962
2962
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
+
2963
2970
def sub (self , match : re .Match ) -> str :
2964
2971
syntax = match .group (1 )
2965
2972
text : str = match .string [match .start (): match .end ()]
2966
2973
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
2971
2977
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
2977
2985
# if no underscores are present, the text is fine and we can just leave it alone
2978
2986
return super ().sub (match )
2979
2987
0 commit comments