From 1b08fdb508937ec3e7667e37673d6cac8490eb84 Mon Sep 17 00:00:00 2001 From: "Rob G. Healey" Date: Thu, 17 Feb 2011 07:42:37 +0000 Subject: [PATCH] Removed the html_escape code from libhtml and using saxutils for escaping characters. Thank you, Gerald Britton, for the better way. svn: r16639 --- src/plugins/lib/libhtml.py | 40 --------------------------- src/plugins/webreport/NarrativeWeb.py | 4 +-- 2 files changed, 2 insertions(+), 42 deletions(-) diff --git a/src/plugins/lib/libhtml.py b/src/plugins/lib/libhtml.py index cd20776d0..7d774ffc2 100644 --- a/src/plugins/lib/libhtml.py +++ b/src/plugins/lib/libhtml.py @@ -104,46 +104,6 @@ _START_CLOSE = set([ 'param' ]) -_html_dbl_quotes = re.compile(r'([^"]*) " ([^"]*) " (.*)', re.VERBOSE) -_html_sng_quotes = re.compile(r"([^']*) ' ([^']*) ' (.*)", re.VERBOSE) -_html_replacement = { - "&" : "&", - ">" : ">", - "<" : "<", - "°" : "", - } - -#------------------------------------------------------------------------ -# html_ecape function -#----------------------------------------------------------------------- -# This command then defines the 'html_escape' option for escaping -# special characters for presentation in HTML based on the above list. -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]) - - # Deal with double quotes. - while 1: - 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) - if not m: - break - text = m.group(1) + '‘' + m.group(2) + '’' + m.group(3) - # Replace remaining single quotes. - text = text.replace("'", ''') - - return text #------------------------------------------------------------------------ # # Html class. diff --git a/src/plugins/webreport/NarrativeWeb.py b/src/plugins/webreport/NarrativeWeb.py index 69f265c8e..67f0ae4f0 100644 --- a/src/plugins/webreport/NarrativeWeb.py +++ b/src/plugins/webreport/NarrativeWeb.py @@ -103,8 +103,8 @@ from libhtmlconst import _CHARACTER_SETS, _CC, _COPY_OPTIONS # src/plugins/lib/libhtml.py from libhtml import Html -#import the html_escape function -from libhtml import html_escape as html_escape +# ability to escape characters from html output +from xml.sax.saxutils import escape as html_escape # import styled notes from # src/plugins/lib/libhtmlbackend.py