[Python-checkins] r61068 - doctools/trunk/sphinx/highlighting.py
georg.brandl
python-checkins at python.org
Mon Feb 25 21:10:24 CET 2008
Author: georg.brandl
Date: Mon Feb 25 21:10:24 2008
New Revision: 61068
Modified:
doctools/trunk/sphinx/highlighting.py
Log:
Fix if no pygments available.
Modified: doctools/trunk/sphinx/highlighting.py
==============================================================================
--- doctools/trunk/sphinx/highlighting.py (original)
+++ doctools/trunk/sphinx/highlighting.py Mon Feb 25 21:10:24 2008
@@ -55,6 +55,16 @@
_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 @@
if self.dest == 'html':
return '<pre>' + cgi.escape(source) + '</pre>\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':
More information about the Python-checkins
mailing list