@@ -247,8 +247,7 @@ def kill_all(*_):
247247 repl_procs .clear ()
248248
249249
250- def create_image (document , line ):
251- # TODO : support image options
250+ def create_image (document , line , image_options ):
252251 imgpath = line [10 :]
253252 confdir = document .settings .env .app .confdir # source root
254253 rst_file = document .attributes ["source" ] # source file path
@@ -258,14 +257,15 @@ def create_image(document, line):
258257 )
259258 img_relpath = os .path .relpath (imgpath , rst_outdir )
260259 uri = directives .uri (img_relpath .replace ("\\ " , "/" ))
261- return nodes .image (line , uri = uri )
260+ return nodes .image (line , uri = uri , ** image_options )
262261
263262
264- def create_mpl_container_node (document , lines ):
263+ def create_mpl_container_node (document , lines , options ):
264+ image_options = {k [6 :]: v for k , v in options .items () if k .startswith ("image_" )}
265265 return nodes .container (
266266 "" ,
267267 * (
268- create_image (document , line )
268+ create_image (document , line , image_options )
269269 for line in lines
270270 if line .startswith ("#repl:img:" )
271271 ),
@@ -368,6 +368,7 @@ class REPL(Directive):
368368 "hide-input" : _option_boolean ,
369369 "hide-output" : _option_boolean ,
370370 ** create_mpl_option_spec (),
371+ ** create_image_option_spec (),
371372 }
372373
373374 def run (self ):
@@ -403,7 +404,9 @@ def run(self):
403404 def to_node (block ):
404405 if block [0 ].startswith ("#repl:img:" ):
405406 # generated new image
406- return create_mpl_container_node (self .state_machine .document , lines )
407+ return create_mpl_container_node (
408+ self .state_machine .document , lines , self .options
409+ )
407410 else :
408411 s = "\n " .join (block )
409412 return nodes .doctest_block (s , s , language = "python" )
@@ -415,7 +418,7 @@ class REPL_Quiet(Directive):
415418 has_content = True
416419 required_arguments = 0
417420 optional_arguments = 0
418- option_spec = create_mpl_option_spec ()
421+ option_spec = { ** create_mpl_option_spec (), ** create_image_option_spec ()}
419422
420423 def run (self ):
421424 # dump the content on REPL & ignore what's printed on the interpreter
@@ -430,7 +433,9 @@ def run(self):
430433 lines = proc .communicate (self .content , show_input = False , show_output = False )
431434
432435 # only return the image lines
433- return [create_mpl_container_node (self .state_machine .document , lines )]
436+ return [
437+ create_mpl_container_node (self .state_machine .document , lines , self .options )
438+ ]
434439
435440
436441def mpl_init (app , config ):
0 commit comments