summaryrefslogtreecommitdiff
path: root/sphinx/highlighting.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-01-06 15:42:13 +0100
committerGeorg Brandl <georg@python.org>2010-01-06 15:42:13 +0100
commite33c80832081e9c23d851d79dc7d95cf3a672cd9 (patch)
treeb24dd7471b1071bf59b323145fdd1ff2324c5834 /sphinx/highlighting.py
parent0c79ced8321faae177f9fccc070edfa18718a039 (diff)
downloadsphinx-e33c80832081e9c23d851d79dc7d95cf3a672cd9.tar.gz
Restore compatibility with Pygments >= 1.2.
Diffstat (limited to 'sphinx/highlighting.py')
-rw-r--r--sphinx/highlighting.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py
index 3f029dc7..3de96880 100644
--- a/sphinx/highlighting.py
+++ b/sphinx/highlighting.py
@@ -20,7 +20,7 @@ except ImportError:
# parser is not available on Jython
parser = None
-from sphinx.util.texescape import tex_hl_escape_map
+from sphinx.util.texescape import tex_hl_escape_map_old, tex_hl_escape_map_new
try:
import pygments
@@ -127,7 +127,7 @@ class PygmentsBridge(object):
# first, escape highlighting characters like Pygments does
source = source.translate(escape_hl_chars)
# then, escape all characters nonrepresentable in LaTeX
- source = source.translate(tex_hl_escape_map)
+ source = source.translate(tex_hl_escape_map_old)
return '\\begin{Verbatim}[commandchars=@\\[\\]]\n' + \
source + '\\end{Verbatim}\n'
@@ -204,7 +204,10 @@ class PygmentsBridge(object):
return highlight(source, lexer, self.fmter[bool(linenos)])
else:
hlsource = highlight(source, lexer, self.fmter[bool(linenos)])
- return hlsource.translate(tex_hl_escape_map)
+ if hlsource.startswith(r'\begin{Verbatim}[commandchars=\\\{\}'):
+ # Pygments >= 1.2
+ return hlsource.translate(tex_hl_escape_map_new)
+ return hlsource.translate(tex_hl_escape_map_old)
except ErrorToken:
# this is most probably not the selected language,
# so let it pass unhighlighted