code: def convert_rst_file_to_notebook(
      rst_file,
      notebook_fname,
      framework=None,
      img_prefix=None,
      origin_folder=None,
      dest_folder=None,
  ):
      r"""
      Convert rst_file to a notebook named notebook_fname.
  
      Args:
          - rst_file (:obj:`str`):
              The doc file to convert (in rst format).
          - notebook_fname (:obj:`str`):
              The output notebook file name (will be replaced if it exists).
          - framework (:obj:`str`, `optional`):
              If provided, must be :obj:`"pt"` or :obj:`"tf"`. In this case, only the PyTorch (resp. TensorFlow) version
              of the code is kept.
          - img_prefix (:obj:`str`, `optional`):
              If provided, will be inserted at the beginning of each image filename (in the `pytorch` or `tensorflow`
              folder, we need to add ../ to each image file to find them).
          - origin_folder (:obj:`str`, `optional`):
              If provided in conjunction with :obj:`dest_folder`, images encountered will be copied from this folder to
              :obj:`dest_folder`.
          - dest_folder (:obj:`str`, `optional`):
              If provided in conjunction with :obj:`origin_folder`, images encountered will be copied from
              :obj:`origin_folder` to this folder.
      """
      with open(rst_file, "r") as f:
          content = f.read()
      lines = content.split("\n")
      lines = process_titles(lines)
      blocks = split_blocks(lines)
      cells = [code_cell(INSTALL_CODE)]
      for block, block_type in blocks:
          if block_type == "title" or block_type == "prose":
              block = convert_table(
                  convert_rst_formatting(convert_rst_links(block))
              )
              cells.append(markdown_cell(block))
          elif block_type == "anchor":
              block = convert_anchor(block)
              cells.append(markdown_cell(block))
          elif block_type.startswith("code-block"):
              codes = split_frameworks(block)
              if framework == "pt" and len(codes) > 1:
                  codes = (rm_first_line(codes[0]),)
              elif framework == "tf" and len(codes) > 1:
                  codes = (rm_first_line(codes[1]),)
              for code in codes:
                  source, output = parse_code_and_output(code)
                  if block_type.endswith("bash"):
                      lines = source.split("\n")
                      new_lines = [
                          line if line.startswith("#") else f"! {line}"
                          for line in lines
                      ]
                      source = "\n".join(new_lines)
                  cells.append(code_cell(source, output=output))
          elif block_type.startswith("image"):
              image_name = block_type[len("image ") :]
              block = convert_image(
                  image_name,
                  block,
                  pref=img_prefix,
                  origin_folder=origin_folder,
                  dest_folder=dest_folder,
              )
              cells.append(markdown_cell(block))
          elif block_type == "math":
              block = convert_math(block)
              cells.append(markdown_cell(block))
          else:
              block = convert_rst_formatting(convert_rst_links(block))
              block = convert_to_note(block, block_type)
              cells.append(markdown_cell(block))
  
      notebook = create_notebook(cells)
      nbformat.write(notebook, notebook_fname, version=4)
  
imports: import nbformat
  import os
  import re
  import shutil
label_desc: Use image node_id 17 for calling a global function with example usage: convert_rst_file_to_notebook(rst_file, notebook_fname, framework, img_prefix, origin_folder, dest_folder) without return types