122122 memoized ,
123123 xml_oneliner_re_from_tab_width ,
124124 hr_tag_re_from_tab_width ,
125+ xml_escape_attr ,
125126)
126127
127128# ---- globals
@@ -1501,7 +1502,7 @@ def _do_links(self, text):
15011502 .replace ('_' , self ._escape_table ['_' ])
15021503 if title :
15031504 title_str = ' title="%s"' % (
1504- _xml_escape_attr ( title )
1505+ xml_escape_attr ( _AMPERSAND_RE , title )
15051506 .replace ('*' , self ._escape_table ['*' ])
15061507 .replace ('_' , self ._escape_table ['_' ]))
15071508 else :
@@ -1510,7 +1511,7 @@ def _do_links(self, text):
15101511 img_class_str = self ._html_class_str_from_tag ("img" )
15111512 result = '<img src="%s" alt="%s"%s%s%s' \
15121513 % (_html_escape_url (url , safe_mode = self .safe_mode ),
1513- _xml_escape_attr ( link_text ),
1514+ xml_escape_attr ( _AMPERSAND_RE , link_text ),
15141515 title_str ,
15151516 img_class_str ,
15161517 self .empty_element_suffix )
@@ -1556,7 +1557,7 @@ def _do_links(self, text):
15561557 .replace ('_' , self ._escape_table ['_' ])
15571558 title = self .titles .get (link_id )
15581559 if title :
1559- title = _xml_escape_attr ( title ) \
1560+ title = xml_escape_attr ( _AMPERSAND_RE , title ) \
15601561 .replace ('*' , self ._escape_table ['*' ]) \
15611562 .replace ('_' , self ._escape_table ['_' ])
15621563 title_str = ' title="%s"' % title
@@ -1566,7 +1567,7 @@ def _do_links(self, text):
15661567 img_class_str = self ._html_class_str_from_tag ("img" )
15671568 result = '<img src="%s" alt="%s"%s%s%s' \
15681569 % (_html_escape_url (url , safe_mode = self .safe_mode ),
1569- _xml_escape_attr ( link_text ),
1570+ xml_escape_attr ( _AMPERSAND_RE , link_text ),
15701571 title_str ,
15711572 img_class_str ,
15721573 self .empty_element_suffix )
@@ -2481,23 +2482,6 @@ class UnicodeWithAttrs(str):
24812482 toc_html = None
24822483
24832484
2484- def _xml_escape_attr (attr , skip_single_quote = True ):
2485- """Escape the given string for use in an HTML/XML tag attribute.
2486-
2487- By default this doesn't bother with escaping `'` to `'`, presuming that
2488- the tag attribute is surrounded by double quotes.
2489- """
2490- escaped = _AMPERSAND_RE .sub ('&' , attr )
2491-
2492- escaped = (attr
2493- .replace ('"' , '"' )
2494- .replace ('<' , '<' )
2495- .replace ('>' , '>' ))
2496- if not skip_single_quote :
2497- escaped = escaped .replace ("'" , "'" )
2498- return escaped
2499-
2500-
25012485def _xml_encode_email_char_at_random (ch ):
25022486 r = random ()
25032487 # Roughly 10% raw, 45% hex, 45% dec.
0 commit comments