ipylab icon indicating copy to clipboard operation
ipylab copied to clipboard

Convert notebook with ipylab

Open simbalsyd opened this issue 2 years ago • 2 comments

Hi,

Usually I am using nbconvert to convert a notebook to html. Today I was searching for a way to do it via code from inside the notebook. When searching for it I found ipylab and the command "notebook:export-to-format" but I don't understand how to use it.

From the notebook I did

from ipylab import JupyterFrontEnd
app = JupyterFrontEnd()
app.commands.execute("docmanager:save")
app.commands.execute("notebook:export-to-format")

I get no error messages but also no file.

What I eventually would like to do is something corresponding to nbconvert --to html --template classic --no-input notebook

Do you have any idea on how to do it?

simbalsyd avatar Aug 27 '22 13:08 simbalsyd

Thanks @simbalsyd.

It should be possible to use the following to export the current notebook to HTML:

app.commands.execute('notebook:export-to-format', {
    'format': 'html',
})

https://user-images.githubusercontent.com/591645/187077772-8f28a449-cc1d-4640-97fa-8f5a58c3c769.mp4

Not sure it would support setting the template or --no-input flag. Or maybe by combining it with https://github.com/timkpaine/jupyterlab_commands.

jtpio avatar Aug 28 '22 14:08 jtpio

Thanks a lot @jtpio, this helped me a lot.

Can you also provide an example to provide the location where we can export the file (If it's possible)

anstiwar avatar Jan 24 '23 14:01 anstiwar