Fix if no pygments available.

This commit is contained in:
Georg Brandl 2008-02-25 20:10:24 +00:00
parent 38690f6af9
commit 198c8e7271

View File

@ -55,6 +55,16 @@ else:
_lexer.add_filter('raiseonerror') _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): class PygmentsBridge(object):
def __init__(self, dest='html', stylename='sphinx'): def __init__(self, dest='html', stylename='sphinx'):
if not pygments: if not pygments:
@ -72,7 +82,8 @@ class PygmentsBridge(object):
if self.dest == 'html': if self.dest == 'html':
return '<pre>' + cgi.escape(source) + '</pre>\n' return '<pre>' + cgi.escape(source) + '</pre>\n'
else: else:
return highlight(source, lexers['none'], lfmter) return '\\begin{Verbatim}[commandchars=@\\[\\]]\n' + \
escape_tex(source) + '\\end{Verbatim}\n'
if not pygments: if not pygments:
return unhighlighted() return unhighlighted()
if lang == 'python': if lang == 'python':