Add missing commands if Pygments is not installed.

Bug reported by Ondrej Certik.
This commit is contained in:
Georg Brandl 2008-03-23 19:33:12 +00:00
parent 0de9d7db7a
commit 3135d3802d
2 changed files with 15 additions and 1 deletions

View File

@ -11,6 +11,9 @@ Changes in trunk
files (under _sources) as input files if the source suffix is
``.txt``.
* sphinx.highlighting: Generate correct markup for LaTeX Verbatim
environment escapes even if Pygments is not installed.
Release 0.1.61798 (Mar 23, 2008)
================================

View File

@ -65,6 +65,13 @@ def escape_tex(text):
replace('\x01', '@lb[]').\
replace('\x02', '@rb[]')
# used if Pygments is not available
_LATEX_STYLES = r'''
\newcommand\at{@}
\newcommand\lb{[}
\newcommand\rb{]}
'''
parsing_exceptions = (SyntaxError, UnicodeEncodeError)
if sys.version_info < (2, 5):
@ -139,5 +146,9 @@ class PygmentsBridge(object):
def get_stylesheet(self):
if not pygments:
if self.dest == 'latex':
return _LATEX_STYLES
# no HTML styles needed
return ''
return (self.dest == 'html' and self.hfmter or self.lfmter)[0].get_style_defs()
fmter = (self.dest == 'html' and self.hfmter or self.lfmter)[0]
return fmter.get_style_defs()