def write_notebook_rst(txt, res, fnm, pth):
    """
    Write the converted notebook text `txt` and resources `res` to
    filename `fnm` in directory `pth`.
    """

    # Extended filename used for output images
    extfnm = fnm + '_files'
    # Directory into which output images are written
    extpth = os.path.join(pth, extfnm)
    # Make output image directory if it doesn't exist
    mkdir(extpth)
    # Iterate over output images in resources dict
    for r in res['outputs'].keys():
        # New name for current output image
        rnew = re.sub('output', fnm, r)
        # Partial path for current output image
        rpth = os.path.join(extfnm, rnew)
        # In RST text, replace old output name with the new one
        txt = re.sub('\.\. image:: ' + r, '.. image:: ' + rpth, txt, re.M)
        # Full path of the current output image
        fullrpth = os.path.join(pth, rpth)
        # Write the current output image to disk
        with open(fullrpth, 'wb') as fo:
            fo.write(res['outputs'][r])

    # Remove trailing whitespace in RST text
    txt = re.sub(r'[ \t]+$', '', txt, flags=re.M)

    # Write RST text to disk
    with open(os.path.join(pth, fnm + '.rst'), 'wt') as fo:
        fo.write(txt)
def write_notebook_rst ( txt , res , fnm , pth ) : extfnm = fnm + '_files' extpth = os . path . join ( pth , extfnm ) mkdir ( extpth ) for r in res [ 'outputs' ] . keys ( ) : rnew = re . sub ( 'output' , fnm , r ) rpth = os . path . join ( extfnm , rnew ) txt = re . sub ( '\.\. image:: ' + r , '.. image:: ' + rpth , txt , re . M ) fullrpth = os . path . join ( pth , rpth ) with open ( fullrpth , 'wb' ) as fo : fo . write ( res [ 'outputs' ] [ r ] ) txt = re . sub ( r'[ \t]+$' , '' , txt , flags = re . M ) with open ( os . path . join ( pth , fnm + '.rst' ) , 'wt' ) as fo : fo . write ( txt )
Write the converted notebook text `txt` and resources `res` to
    filename `fnm` in directory `pth`.