Is there a way to save the output of a cell?

This is how I found to do it. To get a PDF it seems necessary to let nbformat generate an HTML document.

import IPython.display as display
from nbconvert.exporters import HTMLExporter

def to_html(md_text, filename):
    """ Convert a string of text in Jupyter-markdown format to an HTML file
    """
    
    # create a markdown notebook node object
    class Dict(dict):
        def __init__(self, **kwargs):
            self.__dict__.update(kwargs)
            self.update(kwargs)
    nb = Dict(
            cells= [Dict(cell_type="markdown", 
                         metadata={}, 
                         source=md_text,
                        )
                   ],
            metadata={},
            nbformat=4,
            nbformat_minor=4,
            )
    # now pass it to nbformat to write as an HtML file
    exporter = HTMLExporter()
    output, resources = exporter.from_notebook_node(nb) 
    with open(filename, 'wb') as f:
        f.write(output.encode('utf8'))

Surprisingly, the HTML file has at least 271KB.