summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2011-09-25 08:39:09 +0200
committerGeorg Brandl <georg@python.org>2011-09-25 08:39:09 +0200
commit0343ccab089f6351f9ea97548328551e751d557a (patch)
treec26424d7e5ba5a82971b37bcf4d552690061ace6
parent73104e7d962fdabcdbec8c4103209ba1a152bd52 (diff)
downloadsphinx-0343ccab089f6351f9ea97548328551e751d557a.tar.gz
Remove compatibility code for Pygments < 1.2.
-rw-r--r--sphinx/highlighting.py23
-rw-r--r--sphinx/util/texescape.py5
2 files changed, 11 insertions, 17 deletions
diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py
index 0912ee05..25a777ef 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_old, tex_hl_escape_map_new
+from sphinx.util.texescape import tex_hl_escape_map_new
from sphinx.ext import doctest
try:
@@ -54,15 +54,15 @@ else:
_lexer.add_filter('raiseonerror')
-escape_hl_chars = {ord(u'@'): u'@PYGZat[]',
- ord(u'['): u'@PYGZlb[]',
- ord(u']'): u'@PYGZrb[]'}
+escape_hl_chars = {ord(u'\\'): u'\\PYGZbs{}',
+ ord(u'{'): u'\\PYGZob{}',
+ ord(u'}'): u'\\PYGZcb{}'}
# used if Pygments is not available
_LATEX_STYLES = r'''
-\newcommand\PYGZat{@}
-\newcommand\PYGZlb{[}
-\newcommand\PYGZrb{]}
+\newcommand\PYGZbs{\char`\\}
+\newcommand\PYGZob{\char`\{}
+\newcommand\PYGZcb{\char`\}}
'''
parsing_exceptions = (SyntaxError, UnicodeEncodeError)
@@ -112,8 +112,8 @@ 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_old)
- return '\\begin{Verbatim}[commandchars=@\\[\\]]\n' + \
+ source = source.translate(tex_hl_escape_map_new)
+ return '\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n' + \
source + '\\end{Verbatim}\n'
def try_parse(self, src):
@@ -206,11 +206,8 @@ class PygmentsBridge(object):
hlsource = highlight(source, lexer, formatter)
if self.dest == 'html':
return hlsource
- elif hlsource.startswith(r'\begin{Verbatim}[commandchars=\\\{\}'):
- # Pygments >= 1.2
- return hlsource.translate(tex_hl_escape_map_new)
else:
- return hlsource.translate(tex_hl_escape_map_old)
+ return hlsource.translate(tex_hl_escape_map_new)
except ErrorToken:
# this is most probably not the selected language,
# so let it pass unhighlighted
diff --git a/sphinx/util/texescape.py b/sphinx/util/texescape.py
index f968f2e4..1f6f76e6 100644
--- a/sphinx/util/texescape.py
+++ b/sphinx/util/texescape.py
@@ -100,9 +100,7 @@ tex_replacements = [
tex_escape_map = {}
tex_replace_map = {}
-tex_hl_escape_map_old = {} # replacement map for Pygments <= 1.1
-tex_hl_escape_map_new = {} # replacement map for Pygments >= 1.2
-_old_cmd_chars = {ord(u'\\'): u'@', ord(u'{'): u'[', ord(u'}'): u']'}
+tex_hl_escape_map_new = {}
def init():
for a, b in tex_replacements:
@@ -112,4 +110,3 @@ def init():
for a, b in tex_replacements:
if a in u'[]{}\\': continue
tex_hl_escape_map_new[ord(a)] = b
- tex_hl_escape_map_old[ord(a)] = b.translate(_old_cmd_chars)