From 823f23039497d61ae87243a2a5dde46cbdfcc090 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Sun, 15 Mar 2020 23:54:51 +0000 Subject: [PATCH] Add validate_options argument to `parse_directive_text` --- myst_parser/parse_directives.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/myst_parser/parse_directives.py b/myst_parser/parse_directives.py index 1d8d107d..5d0366b9 100644 --- a/myst_parser/parse_directives.py +++ b/myst_parser/parse_directives.py @@ -50,11 +50,16 @@ class DirectiveParsingError(Exception): def parse_directive_text( - directive_class: Type[Directive], argument_str: str, content: str + directive_class: Type[Directive], + argument_str: str, + content: str, + validate_options: bool = True, ): """Parse (and validate) the full directive text.""" if directive_class.option_spec: - body, options = parse_directive_options(content, directive_class) + body, options = parse_directive_options( + content, directive_class, validate=validate_options + ) else: # If there are no possible options, we do not look for a YAML block options = {} @@ -87,7 +92,9 @@ def parse_directive_text( return arguments, options, body_lines -def parse_directive_options(content: str, directive_class: Type[Directive]): +def parse_directive_options( + content: str, directive_class: Type[Directive], validate: bool = True +): """Parse (and validate) the directive option section.""" options = {} if content.startswith("---"): @@ -118,7 +125,7 @@ def parse_directive_options(content: str, directive_class: Type[Directive]): except (yaml.parser.ParserError, yaml.scanner.ScannerError) as error: raise DirectiveParsingError("Invalid options YAML: " + str(error)) - if issubclass(directive_class, TestDirective): + if (not validate) or issubclass(directive_class, TestDirective): # technically this directive spec only accepts one option ('option') # but since its for testing only we accept all options return content, options