Skip to content

Commit 0329edc

Browse files
committed
Fix #1565: Show warning if Pygments throws an ErrorToken
1 parent 5574aba commit 0329edc

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Bugs fixed
1212
* #2243: Ignore strange docstring types for classes, do not crash
1313
* #2247: Fix #2205 breaks make html for definition list with classifiers
1414
that contains regular-expression like string
15+
* #1565: Show warning if Pygments throws an ErrorToken
1516

1617
Release 1.3.4 (released Jan 12, 2016)
1718
=====================================

sphinx/highlighting.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,13 @@ def highlight_block(self, source, lang, opts=None, warn=None, force=False, **kwa
183183
formatter = self.get_formatter(**kwargs)
184184
try:
185185
hlsource = highlight(source, lexer, formatter)
186-
except ErrorToken:
186+
except ErrorToken as exc:
187187
# this is most probably not the selected language,
188188
# so let it pass unhighlighted
189+
if warn:
190+
warn('Could not parse literal_block as "%s". highlighting skipped.' % lang)
191+
else:
192+
raise exc
189193
hlsource = highlight(source, lexers['none'], formatter)
190194
if self.dest == 'html':
191195
return hlsource

tests/root/markup.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ Code blocks
266266
false
267267
end
268268

269+
.. code-block:: c
270+
271+
import sys
272+
273+
sys.stdout.write('hello world!\n')
274+
269275

270276
Misc stuff
271277
----------

tests/test_build_html.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@
3131
reading included file u'.*?wrongenc.inc' seems to be wrong, try giving an \
3232
:encoding: option\\n?
3333
%(root)s/includes.txt:4: WARNING: download file not readable: .*?nonexisting.png
34-
(%(root)s/markup.txt:351: WARNING: invalid single index entry u'')?
34+
(%(root)s/markup.txt:357: WARNING: invalid single index entry u'')?
3535
(%(root)s/undecodable.txt:3: WARNING: undecodable source characters, replacing \
3636
with "\\?": b?'here: >>>(\\\\|/)xbb<<<'
3737
)?"""
3838

3939
HTML_WARNINGS = ENV_WARNINGS + """\
4040
%(root)s/images.txt:20: WARNING: no matching candidate for image URI u'foo.\\*'
41+
%(root)s/markup.txt:269: WARNING: Could not parse literal_block as "c". highlighting skipped.
4142
%(root)s/footnote.txt:60: WARNING: citation not found: missing
4243
%(root)s/markup.txt:158: WARNING: unknown option: &option
4344
"""

tests/test_build_latex.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
%(root)s/markup.txt:158: WARNING: unknown option: &option
2828
%(root)s/footnote.txt:60: WARNING: citation not found: missing
2929
%(root)s/images.txt:20: WARNING: no matching candidate for image URI u'foo.\\*'
30+
%(root)s/markup.txt:269: WARNING: Could not parse literal_block as "c". highlighting skipped.
3031
"""
3132

3233
if PY3:

0 commit comments

Comments
 (0)