def nb2md(ptn, nb, fp):
    """Notebook to Markdown"""
    for ce in nb.get('cells', []):
        ct = ce.get('cell_type')
        sc = ce.get('source')
        if ct == 'markdown':
            sc = ptn.sub('**\\2**', sc)
            fp.write(f'{sc}\n')
        elif ct == 'code':
            ec = ce.get('execution_count') or ' '
            fp.write(f'In [{ec}]:\n\n')
            for s in sc.splitlines():
                fp.write(f'    {s}\n')
            fp.write('\n')
            ops = []
            for op in ce.get('outputs', []):
                tt = op.get('text')
                if tt:
                    fp.write(f'> {tt}\n')
                dc = op.get('data', {})
                if 'image/png' not in dc:
                    for k, v in dc.items():
                        ops.append(v)
            if ops:
                fp.write(f'Out [{ec}]:\n\n    ')
                fp.write('\n    '.join(ops))
                fp.write('\n\n')
