code: def process_docstring(docstring):
      # First, extract code blocks and process them.
      code_blocks = []
      if "```" in docstring:
          tmp = docstring[:]
          while "```" in tmp:
              tmp = tmp[tmp.find("```") :]
              index = tmp[3:].find("```") + 6
              snippet = tmp[:index]
              # Place marker in docstring for later reinjection.
              docstring = docstring.replace(
                  snippet, "$CODE_BLOCK_%d" % len(code_blocks)
              )
              snippet_lines = snippet.split("\n")
              # Remove leading spaces.
              num_leading_spaces = snippet_lines[-1].find("`")
              snippet_lines = [snippet_lines[0]] + [
                  line[num_leading_spaces:]
                  for line in snippet_lines[1:]
              ]
              # Most code snippets have 3 or 4 more leading spaces
              # on inner lines, but not all. Remove them.
              inner_lines = snippet_lines[1:-1]
              leading_spaces = None
              for line in inner_lines:
                  if not line or line[0] == "\n":
                      continue
                  spaces = count_leading_spaces(line)
                  if leading_spaces is None:
                      leading_spaces = spaces
                  if spaces < leading_spaces:
                      leading_spaces = spaces
              if leading_spaces:
                  snippet_lines = (
                      [snippet_lines[0]]
                      + [
                          line[leading_spaces:]
                          for line in snippet_lines[1:-1]
                      ]
                      + [snippet_lines[-1]]
                  )
              snippet = "\n".join(snippet_lines)
              code_blocks.append(snippet)
              tmp = tmp[index:]
  
      # Format docstring lists.
      section_regex = r"\n( +)# (.*)\n"
      section_idx = re.search(section_regex, docstring)
      shift = 0
      sections = {}
      while section_idx and section_idx.group(2):
          anchor = section_idx.group(2)
          leading_spaces = len(section_idx.group(1))
          shift += section_idx.end()
          marker = "$" + anchor.replace(" ", "_") + "$"
          docstring, content = process_list_block(
              docstring, shift, leading_spaces, marker
          )
          sections[marker] = content
          section_idx = re.search(section_regex, docstring[shift:])
  
      # Format docstring section titles.
      docstring = re.sub(
          r"\n(\s+)# (.*)\n", r"\n\1__\2__\n\n", docstring
      )
  
      # Strip all remaining leading spaces.
      lines = docstring.split("\n")
      docstring = "\n".join([line.lstrip(" ") for line in lines])
  
      # Reinject list blocks.
      for marker, content in sections.items():
          docstring = docstring.replace(marker, content)
  
      # Reinject code blocks.
      for i, code_block in enumerate(code_blocks):
          docstring = docstring.replace(
              "$CODE_BLOCK_%d" % i, code_block
          )
      return docstring
  
file_path: hyperopt/docs/autogen.py
imports: import re
  import inspect
  import os
  import shutil
label_desc: Use image node_id 9 for calling a global function with example usage: process_docstring(docstring) and returns: docstring