From: Mike Bayer Date: Tue, 20 Sep 2005 03:43:21 +0000 (+0000) Subject: (no commit message) X-Git-Tag: rel_0_1_0~677 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=733dd5590bfac0c44e4cf71d367b9ffb787c113f;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git --- diff --git a/doc/build/lib/highlight.py b/doc/build/lib/highlight.py index d708488312..50285960ea 100644 --- a/doc/build/lib/highlight.py +++ b/doc/build/lib/highlight.py @@ -94,7 +94,7 @@ def html_escape(string): #return "@" + re.sub(r"([&<>])", lambda m: html_escapes[m.group()], string) + "+" return re.sub(r"([&<>])", lambda m: html_escapes[m.group()], string) -def highlight(source, filename = None, syntaxtype = None): +def highlight(source, filename = None, syntaxtype = None, html_escape = True): if syntaxtype is not None: highlighter = highlighters.get(syntaxtype, None) elif filename is not None: @@ -107,15 +107,19 @@ def highlight(source, filename = None, syntaxtype = None): highlighter = None if highlighter is None: - return html_escape(source) + if html_escape: + return html_escape(source) + else: + return source else: - return highlighter(source).highlight() + return highlighter(source, html_escape = html_escape).highlight() class Highlighter: - def __init__(self, source, output = None): + def __init__(self, source, output = None, html_escape = True): self.source = source self.pos = 0 - + self.html_escape = html_escape + if output is None: self.output = StringIO.StringIO() else: @@ -130,9 +134,15 @@ class Highlighter: def colorize(self, tokens): for pair in tokens: if pair[1] is None: - self.output.write(html_escape(pair[0])) + if self.html_escape: + self.output.write(html_escape(pair[0])) + else: + self.output.write(pair[0]) else: - self.output.write('%s' % (pair[1], html_escape(pair[0]))) + if self.html_escape: + self.output.write('%s' % (pair[1], html_escape(pair[0]))) + else: + self.output.write('%s' % (pair[1], pair[0])) class PythonHighlighter(Highlighter):