diff options
author | Georg Brandl <georg@python.org> | 2014-09-21 16:37:37 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-09-21 16:37:37 +0200 |
commit | db1cf80a69778d882f5c39b8966dc9fd5af256ac (patch) | |
tree | faffe4b50450bd19cab9a06c7cfddb9e4d3b571e /sphinx/highlighting.py | |
parent | 97d2edf3804910eb80a4e172927690e768b80e65 (diff) | |
download | sphinx-git-db1cf80a69778d882f5c39b8966dc9fd5af256ac.tar.gz |
Make pygments unconditional, it is required by setup.py anyway.
Diffstat (limited to 'sphinx/highlighting.py')
-rw-r--r-- | sphinx/highlighting.py | 63 |
1 files changed, 20 insertions, 43 deletions
diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py index 599a76a90..c2d2e89a6 100644 --- a/sphinx/highlighting.py +++ b/sphinx/highlighting.py @@ -24,46 +24,32 @@ from sphinx.util.pycompat import htmlescape from sphinx.util.texescape import tex_hl_escape_map_new from sphinx.ext import doctest -try: - import pygments - from pygments import highlight - from pygments.lexers import PythonLexer, PythonConsoleLexer, CLexer, \ - TextLexer, RstLexer - from pygments.lexers import get_lexer_by_name, guess_lexer - from pygments.formatters import HtmlFormatter, LatexFormatter - from pygments.filters import ErrorToken - from pygments.styles import get_style_by_name - from pygments.util import ClassNotFound - from sphinx.pygments_styles import SphinxStyle, NoneStyle -except ImportError: - pygments = None - lexers = None - HtmlFormatter = LatexFormatter = None -else: - - lexers = dict( - none = TextLexer(), - python = PythonLexer(), - pycon = PythonConsoleLexer(), - pycon3 = PythonConsoleLexer(python3=True), - rest = RstLexer(), - c = CLexer(), - ) - for _lexer in lexers.values(): - _lexer.add_filter('raiseonerror') +from pygments import highlight +from pygments.lexers import PythonLexer, PythonConsoleLexer, CLexer, \ + TextLexer, RstLexer +from pygments.lexers import get_lexer_by_name, guess_lexer +from pygments.formatters import HtmlFormatter, LatexFormatter +from pygments.filters import ErrorToken +from pygments.styles import get_style_by_name +from pygments.util import ClassNotFound +from sphinx.pygments_styles import SphinxStyle, NoneStyle + +lexers = dict( + none = TextLexer(), + python = PythonLexer(), + pycon = PythonConsoleLexer(), + pycon3 = PythonConsoleLexer(python3=True), + rest = RstLexer(), + c = CLexer(), +) +for _lexer in lexers.values(): + _lexer.add_filter('raiseonerror') 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\PYGZbs{\char`\\} -\newcommand\PYGZob{\char`\{} -\newcommand\PYGZcb{\char`\}} -''' - # used if Pygments is available # use textcomp quote to get a true single quote _LATEX_ADD_STYLES = r''' @@ -80,8 +66,6 @@ class PygmentsBridge(object): def __init__(self, dest='html', stylename='sphinx', trim_doctest_flags=False): self.dest = dest - if not pygments: - return if stylename is None or stylename == 'sphinx': style = SphinxStyle elif stylename == 'none': @@ -153,8 +137,6 @@ class PygmentsBridge(object): def highlight_block(self, source, lang, warn=None, force=False, **kwargs): if not isinstance(source, text_type): source = source.decode() - if not pygments: - return self.unhighlighted(source) # find out which lexer to use if lang in ('py', 'python'): @@ -213,11 +195,6 @@ class PygmentsBridge(object): return hlsource.translate(tex_hl_escape_map_new) def get_stylesheet(self): - if not pygments: - if self.dest == 'latex': - return _LATEX_STYLES - # no HTML styles needed - return '' formatter = self.get_formatter() if self.dest == 'html': return formatter.get_style_defs('.highlight') |