code: def script_to_notebook(spth, npth, cr):
      
  
      # Read entire text of example script
      with open(spth) as f:
          stxt = f.read()
      # Process script text
      stxt = preprocess_script_string(stxt)
  
      # If the notebook file exists and has been executed, try to
      # update markdown cells without deleting output cells
      if os.path.exists(npth) and notebook_executed(npth):
          # Read current notebook file
          nbold = nbformat.read(npth, as_version=4)
          # Construct updated notebook
          nbnew = script_string_to_notebook_object(stxt)
          if cr is not None:
              notebook_substitute_ref_with_url(nbnew, cr)
          # If the code cells of the two notebooks match, try to
          # update markdown cells without deleting output cells
          if same_notebook_code(nbnew, nbold):
              try:
                  replace_markdown_cells(nbnew, nbold)
              except Exception:
                  script_string_to_notebook_with_links(stxt, npth, cr)
              else:
                  with open(npth, 'wt') as f:
                      nbformat.write(nbold, f)
          else:
              # Write changed text to output notebook file
              script_string_to_notebook_with_links(stxt, npth, cr)
      else:
          # Write changed text to output notebook file
          script_string_to_notebook_with_links(stxt, npth, cr)
docs: Convert the script at `spth` to a notebook at `npth`. Parameter `cr`
      is a CrossReferenceLookup object.