mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dont crash if pygments raises an exception
This commit is contained in:
parent
022c1ed445
commit
01f9a4a330
@ -75,11 +75,18 @@ def create_lexer(base_class):
|
||||
formats = []
|
||||
if i > 0:
|
||||
# This should never happen
|
||||
state.pygments_stack = None
|
||||
return [(len(text) - i, formats_map(Error))]
|
||||
try:
|
||||
# Pygments lexers expect newlines at the end of the line
|
||||
for pos, token, txt in self.get_tokens_unprocessed(text + '\n', statestack):
|
||||
if txt not in ('\n', ''):
|
||||
formats.append((len(txt), formats_map(token)))
|
||||
except Exception:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
state.pygments_stack = None
|
||||
return [(len(text) - i, formats_map(Error))]
|
||||
|
||||
state.pygments_stack = statestack
|
||||
return formats
|
||||
|
Loading…
x
Reference in New Issue
Block a user