code: def plotly_sg_scraper(block, block_vars, gallery_conf, **kwargs):
      """Scrape Plotly figures for galleries of examples using
      sphinx-gallery.
      Examples should use ``plotly.io.show()`` to display the figure with
      the custom sphinx_gallery renderer.
      Since the sphinx_gallery renderer generates both html and static png
      files, we simply crawl these files and give them the appropriate path.
  
      Original function:
          from plotly.io._sg_scraper import plotly_sg_scraper
      Which is based on:
          https://sphinx-gallery.github.io/stable/advanced.html#example-2-detecting-image-files-on-disk
      Modified to handle the case where examples_dirs is a list of more than one item.
          Original code failed to render plots for multiple directories:
              - Only the rendered the first directory
              - If multiple directories were specified, matplotlib plots in first directory were not rendered
  
      Parameters
      ----------
      block : tuple
          A tuple containing the (label, content, line_number) of the block.
      block_vars : dict
          Dict of block variables.
      gallery_conf : dict
          Contains the configuration of Sphinx-Gallery
      **kwargs : dict
          Additional keyword arguments to pass to
          :meth:`~matplotlib.figure.Figure.savefig`, e.g. ``format='svg'``.
          The ``format`` kwarg in particular is used to set the file extension
          of the output file (currently only 'png' and 'svg' are supported).
      Returns
      -------
      rst : str
          The ReSTructuredText that will be rendered to HTML containing
          the images.
      Notes
      -----
      Add this function to the image scrapers
      """
      examples_dir = os.path.dirname(block_vars["src_file"])
      pngs = sorted(glob(os.path.join(examples_dir, "*.png")))
      htmls = sorted(glob(os.path.join(examples_dir, "*.html")))
      image_path_iterator = block_vars["image_path_iterator"]
      image_names = list()
      seen = set()
      for html, png in zip(htmls, pngs):
          if png not in seen:
              seen |= set(png)
              # the incrementor simply increments the filename as long as html/png are found
              # _001.png, _002.png, _003.png, etc.
              this_image_path_png = next(image_path_iterator)
              this_image_path_html = (
                  os.path.splitext(this_image_path_png)[0] + ".html"
              )
              image_names.append(this_image_path_html)
              shutil.move(png, this_image_path_png)
              shutil.move(html, this_image_path_html)
      # Use the `figure_rst` helper function to generate rST for image files
      return figure_rst(image_names, gallery_conf["src_dir"])
  
file_path: greykite/greykite/common/sphinx_plotly.py
imports: import inspect
  import os
  import shutil
  import warnings
  from glob import glob
  from pathlib import Path
  import plotly
  from plotly.io import write_html
  from plotly.io import write_image
  from plotly.io._base_renderers import ExternalRenderer
  from plotly.tools import return_figure_from_figure_or_data
label_desc: Use image node_id 1 for calling a global function with example usage: plotly_sg_scraper(block, block_vars, gallery_conf) and returns: figure_rst