@@ -1354,9 +1354,23 @@ def _is_comment(token):
13541354 is_html_markup = not is_html_markup
13551355 return '' .join (tokens )
13561356
1357- def _unhash_html_spans (self , text : str ) -> str :
1358- for key , sanitized in list (self .html_spans .items ()):
1359- text = text .replace (key , sanitized )
1357+ def _unhash_html_spans (self , text : str , spans = True , code = False ) -> str :
1358+ '''
1359+ Recursively unhash a block of text
1360+
1361+ Args:
1362+ spans: unhash anything from `self.html_spans`
1363+ code: unhash code blocks
1364+ '''
1365+ orig = ''
1366+ while text != orig :
1367+ if spans :
1368+ for key , sanitized in list (self .html_spans .items ()):
1369+ text = text .replace (key , sanitized )
1370+ if code :
1371+ for code , key in list (self ._code_table .items ()):
1372+ text = text .replace (key , code )
1373+ orig = text
13601374 return text
13611375
13621376 def _sanitize_html (self , s : str ) -> str :
@@ -1582,8 +1596,9 @@ def _do_links(self, text: str) -> str:
15821596
15831597 # We've got to encode these to avoid conflicting
15841598 # with italics/bold.
1585- url = url .replace ('*' , self ._escape_table ['*' ]) \
1586- .replace ('_' , self ._escape_table ['_' ])
1599+ url = self ._unhash_html_spans (url , code = True ) \
1600+ .replace ('*' , self ._escape_table ['*' ]) \
1601+ .replace ('_' , self ._escape_table ['_' ])
15871602 if title :
15881603 title_str = ' title="%s"' % (
15891604 _xml_escape_attr (title )
0 commit comments