def notebook_object_to_rst(ntbk, rpth, cr=None):
    """
    Convert notebook object `ntbk` to rst document at `rpth`, in
    directory `rdir`.  Parameter `cr` is a CrossReferenceLookup
    object.
    """

    # Parent directory of file rpth
    rdir = os.path.dirname(rpth)
    # File basename
    rb = os.path.basename(os.path.splitext(rpth)[0])

    # Pre-process notebook prior to conversion to rst
    if cr is not None:
        preprocess_notebook(ntbk, cr)
    # Convert notebook to rst
    rex = RSTExporter()
    rsttxt, rstres = rex.from_notebook_node(ntbk)
    # Replace `` with ` in sphinx cross-references
    rsttxt = re.sub(r':([^:]+):``(.*?)``', r':\1:`\2`', rsttxt)
    # Insert a cross-reference target at top of file
    reflbl = '.. _examples_' + os.path.basename(rdir) + '_' + \
             rb.replace('-', '_') + ':\n'
    rsttxt = reflbl + rsttxt
    # Write the converted rst to disk
    write_notebook_rst(rsttxt, rstres, rb, rdir)
def notebook_object_to_rst ( ntbk , rpth , cr = None ) : rdir = os . path . dirname ( rpth ) rb = os . path . basename ( os . path . splitext ( rpth ) [ 0 ] ) if cr is not None : preprocess_notebook ( ntbk , cr ) rex = RSTExporter ( ) rsttxt , rstres = rex . from_notebook_node ( ntbk ) rsttxt = re . sub ( r':([^:]+):``(.*?)``' , r':\1:`\2`' , rsttxt ) reflbl = '.. _examples_' + os . path . basename ( rdir ) + '_' + rb . replace ( '-' , '_' ) + ':\n' rsttxt = reflbl + rsttxt write_notebook_rst ( rsttxt , rstres , rb , rdir )
Convert notebook object `ntbk` to rst document at `rpth`, in
    directory `rdir`.  Parameter `cr` is a CrossReferenceLookup
    object.