mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Restore compatibility with Pygments >= 1.2.
This commit is contained in:
2
CHANGES
2
CHANGES
@@ -1,6 +1,8 @@
|
||||
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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -99,8 +99,9 @@ tex_replacements = [
|
||||
]
|
||||
|
||||
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:
|
||||
@@ -108,4 +109,5 @@ def init():
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user