Revert notebook in HTML form back to notebook

I need to convert notebooks that have been exported to the html format back to a notebook form. Does anyone know how I can do this, using something like nbconvert, or where I can find the doccumentaion describing how the conversion happens so I can write my own converter. Anyother relevent advice would be much appreciated.

Many Thanks

It’s my understanding that because of the complexity involved and evolution of the notebook format, it is meant to be one way: .ipynb → HTML.
I mention that by way of prefacing what comes below only as an approach to be used in a pinch. You should endeavor to always keep the original .ipynb files. If you need to conserve space, clear the output, and at least save that in association with the HTML representation.

If your source HTML is fairly standard you can automate / programmatically achieve getting the content back to a form that will work sufficiently. In researching this, I came across something that gives you an idea of what may be necessary here. I’ve actually made a demo notebook stepping through using it with internet files and ‘local’ files. Go here and click launch binder to get started with the demo notebook.


Thank you @fomightez this was really helpful. I had though I would need to understand all of the classes in the span tags like "< span class=“kn”>import< /span > ". but thanks to you code I now see that I don’t need this. Thsi has helped me alot thank you.

1 Like