Simplify html_escape using library escape function and string substitutions
svn: r16751
This commit is contained in:
parent
eff00c25f5
commit
f9179e8186
@ -61,6 +61,7 @@ from textwrap import TextWrapper
|
||||
from unicodedata import normalize
|
||||
from collections import defaultdict
|
||||
import re
|
||||
from xml.sax.saxutils import escape
|
||||
|
||||
import operator
|
||||
from decimal import Decimal
|
||||
@ -202,11 +203,6 @@ CSS = PLUGMAN.process_plugin_data('WEBSTUFF')
|
||||
|
||||
_html_dbl_quotes = re.compile(r'([^"]*) " ([^"]*) " (.*)', re.VERBOSE)
|
||||
_html_sng_quotes = re.compile(r"([^']*) ' ([^']*) ' (.*)", re.VERBOSE)
|
||||
_html_replacement = {
|
||||
"&" : "&",
|
||||
">" : ">",
|
||||
"<" : "<",
|
||||
}
|
||||
|
||||
# This command then defines the 'html_escape' option for escaping
|
||||
# special characters for presentation in HTML based on the above list.
|
||||
@ -214,24 +210,22 @@ def html_escape(text):
|
||||
"""Convert the text and replace some characters with a &# variant."""
|
||||
|
||||
# First single characters, no quotes
|
||||
text = ''.join([_html_replacement.get(c, c) for c in text])
|
||||
text = escape(text)
|
||||
|
||||
# Deal with double quotes.
|
||||
while 1:
|
||||
m = _html_dbl_quotes.match(text)
|
||||
while m:
|
||||
text = "%s" "“" "%s" "”" "%s" % m.groups()
|
||||
m = _html_dbl_quotes.match(text)
|
||||
if not m:
|
||||
break
|
||||
text = m.group(1) + '“' + m.group(2) + '”' + m.group(3)
|
||||
# Replace remaining double quotes.
|
||||
text = text.replace('"', '"')
|
||||
|
||||
# Deal with single quotes.
|
||||
text = text.replace("'s ", '’s ')
|
||||
while 1:
|
||||
m = _html_sng_quotes.match(text)
|
||||
while m:
|
||||
text = "%s" "‘" "%s" "’" "%s" % m.groups()
|
||||
m = _html_sng_quotes.match(text)
|
||||
if not m:
|
||||
break
|
||||
text = m.group(1) + '‘' + m.group(2) + '’' + m.group(3)
|
||||
# Replace remaining single quotes.
|
||||
text = text.replace("'", ''')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user