diff --git a/CHANGES b/CHANGES index d52c68280..c64d86ddc 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,7 @@ Bugs fixed * #2243: Ignore strange docstring types for classes, do not crash * #2247: Fix #2205 breaks make html for definition list with classifiers that contains regular-expression like string +* #1565: Show warning if Pygments throws an ErrorToken Release 1.3.4 (released Jan 12, 2016) ===================================== diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py index 5d2f686dc..aa78b5b2e 100644 --- a/sphinx/highlighting.py +++ b/sphinx/highlighting.py @@ -183,9 +183,13 @@ class PygmentsBridge(object): formatter = self.get_formatter(**kwargs) try: hlsource = highlight(source, lexer, formatter) - except ErrorToken: + except ErrorToken as exc: # this is most probably not the selected language, # so let it pass unhighlighted + if warn: + warn('Could not parse literal_block as "%s". highlighting skipped.' % lang) + else: + raise exc hlsource = highlight(source, lexers['none'], formatter) if self.dest == 'html': return hlsource diff --git a/tests/root/markup.txt b/tests/root/markup.txt index b322b39fa..1700b3844 100644 --- a/tests/root/markup.txt +++ b/tests/root/markup.txt @@ -266,6 +266,12 @@ Code blocks false end +.. code-block:: c + + import sys + + sys.stdout.write('hello world!\n') + Misc stuff ---------- diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 17ea08944..b97d9d57e 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -31,13 +31,14 @@ http://www.python.org/logo.png reading included file u'.*?wrongenc.inc' seems to be wrong, try giving an \ :encoding: option\\n? %(root)s/includes.txt:4: WARNING: download file not readable: .*?nonexisting.png -(%(root)s/markup.txt:351: WARNING: invalid single index entry u'')? +(%(root)s/markup.txt:357: WARNING: invalid single index entry u'')? (%(root)s/undecodable.txt:3: WARNING: undecodable source characters, replacing \ with "\\?": b?'here: >>>(\\\\|/)xbb<<<' )?""" HTML_WARNINGS = ENV_WARNINGS + """\ %(root)s/images.txt:20: WARNING: no matching candidate for image URI u'foo.\\*' +%(root)s/markup.txt:269: WARNING: Could not parse literal_block as "c". highlighting skipped. %(root)s/footnote.txt:60: WARNING: citation not found: missing %(root)s/markup.txt:158: WARNING: unknown option: &option """ diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 5de1c8624..16f55471f 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -27,6 +27,7 @@ LATEX_WARNINGS = ENV_WARNINGS + """\ %(root)s/markup.txt:158: WARNING: unknown option: &option %(root)s/footnote.txt:60: WARNING: citation not found: missing %(root)s/images.txt:20: WARNING: no matching candidate for image URI u'foo.\\*' +%(root)s/markup.txt:269: WARNING: Could not parse literal_block as "c". highlighting skipped. """ if PY3: