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
|
* #901: Emit a warning when using docutils' new "math" markup without a Sphinx
|
||||||
math extension active.
|
math extension active.
|
||||||
|
|
||||||
|
* #845: In code blocks, when the selected lexer fails, display line numbers
|
||||||
|
nevertheless if configured.
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
@ -62,8 +62,8 @@ installed) and handled in a smart way:
|
|||||||
* ``c``
|
* ``c``
|
||||||
* ... and any other lexer name that Pygments supports.
|
* ... and any other lexer name that Pygments supports.
|
||||||
|
|
||||||
* If highlighting with the selected language fails, the block is not highlighted
|
* If highlighting with the selected language fails (i.e. Pygments emits an
|
||||||
in any way.
|
"Error" token), the block is not highlighted in any way.
|
||||||
|
|
||||||
Line numbers
|
Line numbers
|
||||||
^^^^^^^^^^^^
|
^^^^^^^^^^^^
|
||||||
|
@ -175,7 +175,7 @@ class PygmentsBridge(object):
|
|||||||
if self.try_parse(source):
|
if self.try_parse(source):
|
||||||
lexer = lexers['python']
|
lexer = lexers['python']
|
||||||
else:
|
else:
|
||||||
return self.unhighlighted(source)
|
lexer = lexers['none']
|
||||||
else:
|
else:
|
||||||
lexer = lexers['python']
|
lexer = lexers['python']
|
||||||
elif lang in ('python3', 'py3') and source.startswith('>>>'):
|
elif lang in ('python3', 'py3') and source.startswith('>>>'):
|
||||||
@ -185,7 +185,7 @@ class PygmentsBridge(object):
|
|||||||
try:
|
try:
|
||||||
lexer = guess_lexer(source)
|
lexer = guess_lexer(source)
|
||||||
except Exception:
|
except Exception:
|
||||||
return self.unhighlighted(source)
|
lexer = lexers['none']
|
||||||
else:
|
else:
|
||||||
if lang in lexers:
|
if lang in lexers:
|
||||||
lexer = lexers[lang]
|
lexer = lexers[lang]
|
||||||
@ -195,7 +195,7 @@ class PygmentsBridge(object):
|
|||||||
except ClassNotFound:
|
except ClassNotFound:
|
||||||
if warn:
|
if warn:
|
||||||
warn('Pygments lexer name %r is not known' % lang)
|
warn('Pygments lexer name %r is not known' % lang)
|
||||||
return self.unhighlighted(source)
|
lexer = lexers['none']
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
@ -207,19 +207,19 @@ class PygmentsBridge(object):
|
|||||||
source = doctest.doctestopt_re.sub('', source)
|
source = doctest.doctestopt_re.sub('', source)
|
||||||
|
|
||||||
# highlight via Pygments
|
# highlight via Pygments
|
||||||
|
formatter = self.get_formatter(**kwargs)
|
||||||
try:
|
try:
|
||||||
formatter = self.get_formatter(**kwargs)
|
|
||||||
hlsource = highlight(source, lexer, formatter)
|
hlsource = highlight(source, lexer, 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:
|
except ErrorToken:
|
||||||
# this is most probably not the selected language,
|
# this is most probably not the selected language,
|
||||||
# so let it pass unhighlighted
|
# so let it pass unhighlighted
|
||||||
return self.unhighlighted(source)
|
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)
|
||||||
|
|
||||||
def get_stylesheet(self):
|
def get_stylesheet(self):
|
||||||
if not pygments:
|
if not pygments:
|
||||||
|
Loading…
Reference in New Issue
Block a user