Skip to content

Commit

Permalink
Fix #1565: Show warning if Pygments throws an ErrorToken
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Jan 18, 2016
1 parent 5574aba commit 0329edc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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)
=====================================
Expand Down
6 changes: 5 additions & 1 deletion sphinx/highlighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,13 @@ def highlight_block(self, source, lang, opts=None, warn=None, force=False, **kwa
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
Expand Down
6 changes: 6 additions & 0 deletions tests/root/markup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ Code blocks
false
end

.. code-block:: c

import sys

sys.stdout.write('hello world!\n')


Misc stuff
----------
Expand Down
3 changes: 2 additions & 1 deletion tests/test_build_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
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
"""
Expand Down
1 change: 1 addition & 0 deletions tests/test_build_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
%(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:
Expand Down

0 comments on commit 0329edc

Please sign in to comment.