# build out an image directive like # .. image:: somefile.png # :width 4in # # from an input like # savefig somefile.png width=4in
(self, decorator)
| 415 | sys.stdout = stdout |
| 416 | |
| 417 | def process_image(self, decorator): |
| 418 | """ |
| 419 | # build out an image directive like |
| 420 | # .. image:: somefile.png |
| 421 | # :width 4in |
| 422 | # |
| 423 | # from an input like |
| 424 | # savefig somefile.png width=4in |
| 425 | """ |
| 426 | savefig_dir = self.savefig_dir |
| 427 | source_dir = self.source_dir |
| 428 | saveargs = decorator.split(' ') |
| 429 | filename = saveargs[1] |
| 430 | # insert relative path to image file in source |
| 431 | # as absolute path for Sphinx |
| 432 | # sphinx expects a posix path, even on Windows |
| 433 | path = pathlib.Path(savefig_dir, filename) |
| 434 | outfile = '/' + path.relative_to(source_dir).as_posix() |
| 435 | |
| 436 | imagerows = ['.. image:: %s' % outfile] |
| 437 | |
| 438 | for kwarg in saveargs[2:]: |
| 439 | arg, val = kwarg.split('=') |
| 440 | arg = arg.strip() |
| 441 | val = val.strip() |
| 442 | imagerows.append(' :%s: %s'%(arg, val)) |
| 443 | |
| 444 | image_file = os.path.basename(outfile) # only return file name |
| 445 | image_directive = '\n'.join(imagerows) |
| 446 | return image_file, image_directive |
| 447 | |
| 448 | # Callbacks for each type of token |
| 449 | def process_input(self, data, input_prompt, lineno): |