code: def convert_to_sphinx_gallery_format(content):
      """Convert the example file to sphinx-gallery format.
  
      Parameters
      ----------
      content : list of str
          example file content
  
      Returns
      -------
      list of str
          example file content converted to sphinx-gallery format
      """
      inheader = True
      indocs = False
  
      new_content = ""
      for line in content:
          if inheader:
              if not indocs and (
                  line.startswith('"""')
                  or line.startswith("'''")
                  or line.startswith('r"""')
                  or line.startswith("r'''")
              ):
                  new_content += line
                  if len(line.rstrip()) < 5:
                      indocs = True
                  else:
                      # single line doc
                      inheader = False
                  continue
  
              if line.rstrip().endswith(
                  '"""'
              ) or line.rstrip().endswith("'''"):
                  inheader = False
                  indocs = False
  
              new_content += line
              continue
  
          if indocs or (
              line.startswith('"""')
              or line.startswith("'''")
              or line.startswith('r"""')
              or line.startswith("r'''")
          ):
              if not indocs:
                  # guaranteed to start with """
                  if len(line.rstrip()) > 4 and (
                      line.rstrip().endswith('"""')
                      or line.rstrip().endswith("'''")
                  ):
                      # single line doc
                      tmp_line = line.replace('"""', "").replace(
                          "'''", ""
                      )
                      new_content += f"{sphx_glr_sep}\n"
                      new_content += f"# {tmp_line}"
                  else:
                      # must be start of multiline block
                      indocs = True
                      new_content += f"{sphx_glr_sep}\n"
              else:
                  # we are already in the docs
                  # handle doc end
                  if line.rstrip().endswith(
                      '"""'
                  ) or line.rstrip().endswith("'''"):
                      # remove quotes
                      # import ipdb; ipdb.set_trace()
                      indocs = False
                      new_content += "\n"
                  else:
                      # import ipdb; ipdb.set_trace()
                      new_content += f"# {line}"
                      # has to be documentation
              continue
  
          new_content += line
  
      return new_content
  
file_path: dipy/doc/sphinxext/prepare_gallery.py
imports: import fnmatch
  import sys
  import os
  import shutil
  from os.path import join
  from dataclasses import dataclass, field
  from pathlib import Path
  from sphinx.util import logging
label_desc: Use image node_id 3 for calling a global function with example usage: convert_to_sphinx_gallery_format(content) and returns: new_content