code: def rst_to_notebook(infile, outfile):
      
  
      # Read infile into a string
      with open(infile, 'r') as fin:
          rststr = fin.read()
      # Convert string from rst to markdown
      mdfmt = 'markdown_github+tex_math_dollars+fenced_code_attributes'
      mdstr = pypandoc.convert_text(rststr, mdfmt, format='rst',
                                    extra_args=['--atx-headers'])
      # In links, replace .py extensions with .ipynb
      mdstr = re.sub(r'\(([^\)]+).py\)', r'(\1.ipynb)', mdstr)
      # Enclose the markdown within triple quotes and convert from
      # python to notebook
      mdstr = '"""' + mdstr + '"""'
      nb = py2jn.py_string_to_notebook(mdstr)
      py2jn.tools.write_notebook(nb, outfile, nbver=4)
docs: Convert an rst file to a notebook file.