From 198c8e72719e74ab4c6a0cbcaf120f9a37845e18 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Mon, 25 Feb 2008 20:10:24 +0000 Subject: [PATCH] Fix if no pygments available. --- sphinx/highlighting.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py index 7715681da..78e930645 100644 --- a/sphinx/highlighting.py +++ b/sphinx/highlighting.py @@ -55,6 +55,16 @@ else: _lexer.add_filter('raiseonerror') + +def escape_tex(text): + return text.replace('@', '\x00'). \ + replace('[', '\x01'). \ + replace(']', '\x02'). \ + replace('\x00', '@at[]').\ + replace('\x01', '@lb[]').\ + replace('\x02', '@rb[]') + + class PygmentsBridge(object): def __init__(self, dest='html', stylename='sphinx'): if not pygments: @@ -72,7 +82,8 @@ class PygmentsBridge(object): if self.dest == 'html': return '
' + cgi.escape(source) + '
\n' else: - return highlight(source, lexers['none'], lfmter) + return '\\begin{Verbatim}[commandchars=@\\[\\]]\n' + \ + escape_tex(source) + '\\end{Verbatim}\n' if not pygments: return unhighlighted() if lang == 'python':