summaryrefslogtreecommitdiff
path: root/sphinx/highlighting.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2016-12-20 23:21:30 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2017-01-02 12:59:50 +0900
commit85dcd7baa85a04abe2fd571085911cc027b1f7ea (patch)
treed4818afc63ebbd5d45f0e55d6012111c76e128ab /sphinx/highlighting.py
parent6d4e6454093953943e79d4db6efeb17390870e62 (diff)
downloadsphinx-git-85dcd7baa85a04abe2fd571085911cc027b1f7ea.tar.gz
Use sphinx.util.logging instead app.warn()
Diffstat (limited to 'sphinx/highlighting.py')
-rw-r--r--sphinx/highlighting.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py
index 94f562159..493ecb7a7 100644
--- a/sphinx/highlighting.py
+++ b/sphinx/highlighting.py
@@ -11,6 +11,7 @@
from six import text_type
+from sphinx.util import logging
from sphinx.util.pycompat import htmlescape
from sphinx.util.texescape import tex_hl_escape_map_new
from sphinx.ext import doctest
@@ -26,6 +27,8 @@ from pygments.styles import get_style_by_name
from pygments.util import ClassNotFound
from sphinx.pygments_styles import SphinxStyle, NoneStyle
+logger = logging.getLogger(__name__)
+
lexers = dict(
none = TextLexer(stripnl=False),
python = PythonLexer(stripnl=False),
@@ -92,7 +95,7 @@ class PygmentsBridge(object):
return '\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n' + \
source + '\\end{Verbatim}\n'
- def highlight_block(self, source, lang, opts=None, warn=None, force=False, **kwargs):
+ def highlight_block(self, source, lang, opts=None, location=None, force=False, **kwargs):
if not isinstance(source, text_type):
source = source.decode()
@@ -120,11 +123,9 @@ class PygmentsBridge(object):
try:
lexer = lexers[lang] = get_lexer_by_name(lang, **(opts or {}))
except ClassNotFound:
- if warn:
- warn('Pygments lexer name %r is not known' % lang)
- lexer = lexers['none']
- else:
- raise
+ logger.warning('Pygments lexer name %r is not known', lang,
+ location=location)
+ lexer = lexers['none']
else:
lexer.add_filter('raiseonerror')
@@ -137,17 +138,16 @@ class PygmentsBridge(object):
formatter = self.get_formatter(**kwargs)
try:
hlsource = highlight(source, lexer, formatter)
- except ErrorToken as exc:
+ except ErrorToken:
# this is most probably not the selected language,
# so let it pass unhighlighted
if lang == 'default':
pass # automatic highlighting failed.
- elif warn:
- warn('Could not lex literal_block as "%s". '
- 'Highlighting skipped.' % lang,
- type='misc', subtype='highlighting_failure')
else:
- raise exc
+ logger.warning('Could not lex literal_block as "%s". '
+ 'Highlighting skipped.', lang,
+ type='misc', subtype='highlighting_failure',
+ location=location)
hlsource = highlight(source, lexers['none'], formatter)
if self.dest == 'html':
return hlsource