code: def nb_to_md(nb_path, md_path, img_dir, working_dir=None):
      img_exts = ("png", "jpg", "jpeg")
      # Assumes an already populated notebook.
      assert str(md_path).endswith(".md")
      current_dir = os.getcwd()
      original_img_dir = str(img_dir)
      if original_img_dir.endswith("/"):
          original_img_dir = original_img_dir[:-1]
      img_dir = os.path.abspath(img_dir)
      nb_path = os.path.abspath(nb_path)
      nb_fname = str(nb_path).split("/")[-1]
  
      del_working_dir = False
      if working_dir is None:
          del_working_dir = True
          working_dir = "tmp_" + str(random.randint(1e6, 1e7))
      if not os.path.exists(working_dir):
          os.makedirs(working_dir)
      print("Using working_dir:", working_dir)
  
      os.chdir(working_dir)
      shutil.copyfile(nb_path, nb_fname)
  
      md_name = str(md_path).split("/")[-1][:-3]
      target_md = md_name + ".md"
      img_dir = Path(img_dir) / md_name
      if not os.path.exists(img_dir):
          os.makedirs(img_dir)
  
      os.system(
          # "jupyter nbconvert --to markdown --execute --debug "
          "jupyter nbconvert --to markdown "
          + nb_fname
          + " --output "
          + target_md
          # + " --ExecutePreprocessor.timeout="
          # + str(TIMEOUT)
      )
      tmp_img_dir = md_name + "_files"
      if os.path.exists(tmp_img_dir):
          for fname in os.listdir(tmp_img_dir):
              if fname.endswith(img_exts):
                  src = Path(tmp_img_dir) / fname
                  target = Path(img_dir) / fname
                  print("copy", src, "to", target)
                  shutil.copyfile(src, target)
      os.chdir(current_dir)
      md_content = open(Path(working_dir) / (md_name + ".md")).read()
      for ext in img_exts:
          md_content = md_content.replace(
              "![" + ext + "](" + md_name + "_files",
              "![" + ext + "](" + original_img_dir + "/" + md_name,
          )
      md_content = _make_output_code_blocks(md_content)
      open(md_path, "w").write(md_content)
      if del_working_dir:
          shutil.rmtree(working_dir)
  
file_path: autokeras/docs/tutobooks.py
imports: import json
  import os
  import random
  import shutil
  import sys
  from pathlib import Path
label_desc: Use image node_id 3 for calling a global function with example usage: nb_to_md(nb_path, md_path, img_dir, working_dir) without return types