@@ -47,7 +47,7 @@ except:
4747import codecs
4848import io
4949
50- from docutils import nodes
50+ from docutils import nodes , utils
5151from docutils .parsers .rst import directives , roles
5252from docutils .parsers .rst .directives .body import CodeBlock , Directive
5353from docutils .core import publish_parts
@@ -76,6 +76,35 @@ from docutils import nodes
7676original_behavior = False # Documents original docutils behavior
7777github_display = True
7878
79+ def extract_extension_options (field_list , option_spec ):
80+ """
81+ Overrides `utils.extract_extension_options` and inlines
82+ `utils.assemble_option_dict` to make it ignore unknown options passed to
83+ directives (i.e. ``:caption:`` for ``.. code-block:``).
84+ """
85+
86+ dropped = set ()
87+ options = {}
88+ for name , value in utils .extract_options (field_list ):
89+ convertor = option_spec .get (name )
90+ if name in options or name in dropped :
91+ raise utils .DuplicateOptionError ('duplicate option "%s"' % name )
92+
93+ # silently drop unknown options as long as they are not duplicates
94+ if convertor is None :
95+ dropped .add (name )
96+ continue
97+
98+ # continue as before
99+ try :
100+ options [name ] = convertor (value )
101+ except (ValueError , TypeError ) as detail :
102+ raise detail .__class__ ('(option: "%s"; value: %r)\n %s'
103+ % (name , value , ' ' .join (detail .args )))
104+ return options
105+
106+ utils .extract_extension_options = extract_extension_options
107+
79108def unknown_directive (self , type_name ):
80109 lineno = self .state_machine .abs_line_number ()
81110 indented , indent , offset , blank_finish = \
0 commit comments