Jupyter Notebook: save all images to svg by program

Viewed 8847

When I click the Download as markdown in the menu,

enter image description here

it will give me zip file with .md, .png, '.svg'

enter image description here

Note: I use set_matplotlib_formats('png', 'svg'), so the download file returns 2 image file formats.

Now, I want to save all the images in this notebook into svg by program (i.e., writing Python script), how can I do it? Maybe something like

save_images_to_svg('this_notebook.ipynb')
# and it will save all images to '.\images\*.svg'

What I know so far:

The link for Download as markdown is at here

    this.element.find('#download_markdown').click(function () {
        that._nbconvert('markdown', true);
    });

It further binds to the _nbconvert at here

MenuBar.prototype._nbconvert = function (format, download) {
    download = download || false;
    var notebook_path = utils.encode_uri_components(this.notebook.notebook_path);
    var url = utils.url_path_join(
        this.base_url,
        'nbconvert',
        format,
        notebook_path
    ) + "?download=" + download.toString();

    this._new_window(url);
    };

This means that the notebook sends a request to the backend to do the conversion.

I don't know where it is, but it seems like here, because it has a respond_zip method.

I think a quick hack is simply to download the file using python with the url from MenuBar.prototype._nbconvert.

1 Answers
Related