From 543261843706be1d7af35ed0e9e979b87e43538c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 29 Mar 2019 11:35:31 +0100 Subject: [PATCH] m.htmlsanity: graceful docutils error handling in the render_rst filter. Like I did for Pelican 4. --- pelican-plugins/m/htmlsanity.py | 3 ++- .../m/test/htmlsanity_parse_error/page.rst | 2 ++ pelican-plugins/m/test/test_htmlsanity.py | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 pelican-plugins/m/test/htmlsanity_parse_error/page.rst diff --git a/pelican-plugins/m/htmlsanity.py b/pelican-plugins/m/htmlsanity.py index 38deabd5..85d68e06 100644 --- a/pelican-plugins/m/htmlsanity.py +++ b/pelican-plugins/m/htmlsanity.py @@ -656,7 +656,8 @@ def render_rst(value): 'syntax_highlight': 'short', 'input_encoding': 'utf-8', 'language_code': settings['DEFAULT_LANG'], - 'exit_status_level': 2, + 'halt_level': 2, + 'traceback': True, 'embed_stylesheet': False} if settings['DOCUTILS_SETTINGS']: extra_params.update(settings['DOCUTILS_SETTINGS']) diff --git a/pelican-plugins/m/test/htmlsanity_parse_error/page.rst b/pelican-plugins/m/test/htmlsanity_parse_error/page.rst new file mode 100644 index 00000000..34bfa2d5 --- /dev/null +++ b/pelican-plugins/m/test/htmlsanity_parse_error/page.rst @@ -0,0 +1,2 @@ +Hello +##### diff --git a/pelican-plugins/m/test/test_htmlsanity.py b/pelican-plugins/m/test/test_htmlsanity.py index ea8c989c..90efe87c 100644 --- a/pelican-plugins/m/test/test_htmlsanity.py +++ b/pelican-plugins/m/test/test_htmlsanity.py @@ -109,3 +109,20 @@ class TypographyGlobalLang(PluginTestCase): # The lang element should be set correctly and the ­ should # be at proper places and not where it shouldn't be. self.assertEqual(*self.actual_expected_contents('page.html')) + +class RenderRst(PluginTestCase): + def __init__(self, *args, **kwargs): + super().__init__(__file__, 'parse_error', *args, **kwargs) + + def test_parse_error(self): + # Verify that the parse error in M_FINE_PRINT raises an Exception, not + # nothing and not SystemExit or some such + with self.assertRaisesRegex(Exception, "underline too short"): + self.run_pelican({ + 'PLUGINS': ['m.htmlsanity'], + 'M_FINE_PRINT': """ +Page with a parse error +############# + +The underline is too short. +"""}) -- 2.30.2