From 61f1154f232c89d5e8d17ca56616e42e328db7eb Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Fri, 6 Aug 2021 05:50:01 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Fail=20gracefully=20o?= =?UTF-8?q?n=20non-dict=20front-matter=20(#409)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- myst_parser/docutils_renderer.py | 7 ++++++- myst_parser/sphinx_renderer.py | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/myst_parser/docutils_renderer.py b/myst_parser/docutils_renderer.py index 1be2fda9..cfd75230 100644 --- a/myst_parser/docutils_renderer.py +++ b/myst_parser/docutils_renderer.py @@ -609,7 +609,12 @@ def render_front_matter(self, token: SyntaxTreeNode) -> None: if not isinstance(token.content, dict): try: data = yaml.safe_load(token.content) - except (yaml.parser.ParserError, yaml.scanner.ScannerError) as error: + assert isinstance(data, dict), "not dict" + except ( + AssertionError, + yaml.parser.ParserError, + yaml.scanner.ScannerError, + ) as error: msg_node = self.reporter.error( "Front matter block:\n" + str(error), line=position ) diff --git a/myst_parser/sphinx_renderer.py b/myst_parser/sphinx_renderer.py index 513eee6e..a2b7ebe5 100644 --- a/myst_parser/sphinx_renderer.py +++ b/myst_parser/sphinx_renderer.py @@ -192,7 +192,11 @@ class MockSphinx(Sphinx): def __init__(self, confoverrides=None, srcdir=None, raise_on_warning=False): self.extensions = {} self.registry = SphinxComponentRegistry() - self.html_themes = {} + try: + self.html_themes = {} + except AttributeError: + # changed to property in sphinx 4.1 + pass self.events = EventManager(self) # logging