122
122
memoized ,
123
123
xml_oneliner_re_from_tab_width ,
124
124
hr_tag_re_from_tab_width ,
125
+ xml_escape_attr ,
125
126
)
126
127
127
128
# ---- globals
@@ -1501,7 +1502,7 @@ def _do_links(self, text):
1501
1502
.replace ('_' , self ._escape_table ['_' ])
1502
1503
if title :
1503
1504
title_str = ' title="%s"' % (
1504
- _xml_escape_attr ( title )
1505
+ xml_escape_attr ( _AMPERSAND_RE , title )
1505
1506
.replace ('*' , self ._escape_table ['*' ])
1506
1507
.replace ('_' , self ._escape_table ['_' ]))
1507
1508
else :
@@ -1510,7 +1511,7 @@ def _do_links(self, text):
1510
1511
img_class_str = self ._html_class_str_from_tag ("img" )
1511
1512
result = '<img src="%s" alt="%s"%s%s%s' \
1512
1513
% (_html_escape_url (url , safe_mode = self .safe_mode ),
1513
- _xml_escape_attr ( link_text ),
1514
+ xml_escape_attr ( _AMPERSAND_RE , link_text ),
1514
1515
title_str ,
1515
1516
img_class_str ,
1516
1517
self .empty_element_suffix )
@@ -1556,7 +1557,7 @@ def _do_links(self, text):
1556
1557
.replace ('_' , self ._escape_table ['_' ])
1557
1558
title = self .titles .get (link_id )
1558
1559
if title :
1559
- title = _xml_escape_attr ( title ) \
1560
+ title = xml_escape_attr ( _AMPERSAND_RE , title ) \
1560
1561
.replace ('*' , self ._escape_table ['*' ]) \
1561
1562
.replace ('_' , self ._escape_table ['_' ])
1562
1563
title_str = ' title="%s"' % title
@@ -1566,7 +1567,7 @@ def _do_links(self, text):
1566
1567
img_class_str = self ._html_class_str_from_tag ("img" )
1567
1568
result = '<img src="%s" alt="%s"%s%s%s' \
1568
1569
% (_html_escape_url (url , safe_mode = self .safe_mode ),
1569
- _xml_escape_attr ( link_text ),
1570
+ xml_escape_attr ( _AMPERSAND_RE , link_text ),
1570
1571
title_str ,
1571
1572
img_class_str ,
1572
1573
self .empty_element_suffix )
@@ -2481,23 +2482,6 @@ class UnicodeWithAttrs(str):
2481
2482
toc_html = None
2482
2483
2483
2484
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
-
2501
2485
def _xml_encode_email_char_at_random (ch ):
2502
2486
r = random ()
2503
2487
# Roughly 10% raw, 45% hex, 45% dec.
0 commit comments