mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Relax Pygments parsing on lexing failures
This commit is contained in:
parent
7e9a2066c2
commit
7d8df06e19
1
CHANGES
1
CHANGES
@ -66,6 +66,7 @@ Bugs fixed
|
|||||||
* #11546: Translated nodes identical to their original text are now marked
|
* #11546: Translated nodes identical to their original text are now marked
|
||||||
with the ``translated=True`` attribute.
|
with the ``translated=True`` attribute.
|
||||||
* #10049: html: Change "Permalink" to "Link" for title text in link anchors.
|
* #10049: html: Change "Permalink" to "Link" for title text in link anchors.
|
||||||
|
* #4225: Relax Pygments parsing on lexing failures.
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
-------
|
-------
|
||||||
|
@ -164,17 +164,23 @@ class PygmentsBridge:
|
|||||||
formatter = self.get_formatter(**kwargs)
|
formatter = self.get_formatter(**kwargs)
|
||||||
try:
|
try:
|
||||||
hlsource = highlight(source, lexer, formatter)
|
hlsource = highlight(source, lexer, formatter)
|
||||||
except ErrorToken:
|
except ErrorToken as err:
|
||||||
# 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 un highlighted
|
||||||
if lang == 'default':
|
if lang == 'default':
|
||||||
pass # automatic highlighting failed.
|
lang = 'none' # automatic highlighting failed.
|
||||||
else:
|
else:
|
||||||
logger.warning(__('Could not lex literal_block %r as "%s". '
|
logger.warning(
|
||||||
'Highlighting skipped.'), source, lang,
|
__('Lexing literal_block %r as "%s" resulted in an error at token: %r. '
|
||||||
type='misc', subtype='highlighting_failure',
|
'Retrying in relaxed mode.'),
|
||||||
location=location)
|
source, lang, str(err),
|
||||||
lexer = self.get_lexer(source, 'none', opts, force, location)
|
type='misc', subtype='highlighting_failure',
|
||||||
|
location=location)
|
||||||
|
if force:
|
||||||
|
lang = 'none'
|
||||||
|
else:
|
||||||
|
force = True
|
||||||
|
lexer = self.get_lexer(source, lang, opts, force, location)
|
||||||
hlsource = highlight(source, lexer, formatter)
|
hlsource = highlight(source, lexer, formatter)
|
||||||
|
|
||||||
if self.dest == 'html':
|
if self.dest == 'html':
|
||||||
|
@ -97,8 +97,8 @@ def test_default_highlight(logger):
|
|||||||
|
|
||||||
# python: raises error if highlighting failed
|
# python: raises error if highlighting failed
|
||||||
ret = bridge.highlight_block('reST ``like`` text', 'python')
|
ret = bridge.highlight_block('reST ``like`` text', 'python')
|
||||||
logger.warning.assert_called_with('Could not lex literal_block %r as "%s". '
|
logger.warning.assert_called_with('Lexing literal_block %r as "%s" resulted in an error at token: %r. '
|
||||||
'Highlighting skipped.',
|
'Retrying in relaxed mode.',
|
||||||
'reST ``like`` text', 'python',
|
'reST ``like`` text', 'python', '`',
|
||||||
type='misc', subtype='highlighting_failure',
|
type='misc', subtype='highlighting_failure',
|
||||||
location=None)
|
location=None)
|
||||||
|
Loading…
Reference in New Issue
Block a user