mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Closes #845: In code blocks, when the selected lexer fails, display line numbers nevertheless if configured.
This commit is contained in:
parent
2a663ee71c
commit
b29226a060
3
CHANGES
3
CHANGES
@ -46,6 +46,9 @@ Bugs fixed
|
||||
* #901: Emit a warning when using docutils' new "math" markup without a Sphinx
|
||||
math extension active.
|
||||
|
||||
* #845: In code blocks, when the selected lexer fails, display line numbers
|
||||
nevertheless if configured.
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
|
@ -62,8 +62,8 @@ installed) and handled in a smart way:
|
||||
* ``c``
|
||||
* ... and any other lexer name that Pygments supports.
|
||||
|
||||
* If highlighting with the selected language fails, the block is not highlighted
|
||||
in any way.
|
||||
* If highlighting with the selected language fails (i.e. Pygments emits an
|
||||
"Error" token), the block is not highlighted in any way.
|
||||
|
||||
Line numbers
|
||||
^^^^^^^^^^^^
|
||||
|
@ -175,7 +175,7 @@ class PygmentsBridge(object):
|
||||
if self.try_parse(source):
|
||||
lexer = lexers['python']
|
||||
else:
|
||||
return self.unhighlighted(source)
|
||||
lexer = lexers['none']
|
||||
else:
|
||||
lexer = lexers['python']
|
||||
elif lang in ('python3', 'py3') and source.startswith('>>>'):
|
||||
@ -185,7 +185,7 @@ class PygmentsBridge(object):
|
||||
try:
|
||||
lexer = guess_lexer(source)
|
||||
except Exception:
|
||||
return self.unhighlighted(source)
|
||||
lexer = lexers['none']
|
||||
else:
|
||||
if lang in lexers:
|
||||
lexer = lexers[lang]
|
||||
@ -195,7 +195,7 @@ class PygmentsBridge(object):
|
||||
except ClassNotFound:
|
||||
if warn:
|
||||
warn('Pygments lexer name %r is not known' % lang)
|
||||
return self.unhighlighted(source)
|
||||
lexer = lexers['none']
|
||||
else:
|
||||
raise
|
||||
else:
|
||||
@ -207,19 +207,19 @@ class PygmentsBridge(object):
|
||||
source = doctest.doctestopt_re.sub('', source)
|
||||
|
||||
# highlight via Pygments
|
||||
try:
|
||||
formatter = self.get_formatter(**kwargs)
|
||||
try:
|
||||
hlsource = highlight(source, lexer, formatter)
|
||||
except ErrorToken:
|
||||
# this is most probably not the selected language,
|
||||
# so let it pass unhighlighted
|
||||
hlsource = highlight(source, lexers['none'], formatter)
|
||||
if self.dest == 'html':
|
||||
return hlsource
|
||||
else:
|
||||
if not isinstance(hlsource, unicode): # Py2 / Pygments < 1.6
|
||||
hlsource = hlsource.decode()
|
||||
return hlsource.translate(tex_hl_escape_map_new)
|
||||
except ErrorToken:
|
||||
# this is most probably not the selected language,
|
||||
# so let it pass unhighlighted
|
||||
return self.unhighlighted(source)
|
||||
|
||||
def get_stylesheet(self):
|
||||
if not pygments:
|
||||
|
Loading…
Reference in New Issue
Block a user