Commits

Georg Brandl  committed 22d6d61

Restore compatibility with Pygments >= 1.2.

  • Participants
  • Parent commits 7b7a5c6

Comments (0)

Files changed (3)

 Release 0.6.4 (in development)
 ==============================
 
+* Restore compatibility with Pygments >= 1.2.
+
 * #295: Fix escaping of hyperref targets in LaTeX output.
 
 * #302: Fix links generated by the ``:doc:`` role for LaTeX output.

File sphinx/highlighting.py

     # 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
             # 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'
 
                 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

File sphinx/util/texescape.py

 ]
 
 tex_escape_map = {}
-tex_hl_escape_map = {}
-_new_cmd_chars = {ord(u'\\'): u'@', ord(u'{'): u'[', ord(u'}'): u']'}
+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']'}
 
 def init():
     for a, b in tex_replacements:
 
     for a, b in tex_replacements:
         if a in u'[]{}\\': continue
-        tex_hl_escape_map[ord(a)] = b.translate(_new_cmd_chars)
+        tex_hl_escape_map_new[ord(a)] = b
+        tex_hl_escape_map_old[ord(a)] = b.translate(_old_cmd_chars)