nbtohtml is a Go library and CLI for rendering Jupyter Notebooks as HTML.
- Built for server-side rendering (no DOM required)
- Comes with built-in Markdown rendering and syntax highlighting
- Implemented in Go for speed and portability
- Sample styles support light and dark mode
- Output is sanitized to prevent code injection
- Download the latest binary from the Releases page
./nbtohtml convert /path/to/your/notebook.ipynbin the directory where you've downloaded the program
- Compile and install the program by running
go get -u github.com/samuelmeuli/nbtohtml/cmd/nbtohtml
nbtohtml convert /path/to/your/notebook.ipynb
nbtohtmlas a dependency in your Go project:
go get -u github.com/samuelmeuli/nbtohtml
- Use the library in your code:
notebookHTML := new(bytes.Buffer) notebookPath := "/path/to/your/notebook.ipynb" err := nbtohtml.ConvertFile(notebookHTML, notebookPath)
nbtohtml generates HTML tags without inline styles, but with class names. This allows you to style the notebook according to your needs. You will probably want to include some of the following stylesheets in your HTML:
- Jupyter Notebook styles: Styles for the Jupyter Notebook (e.g. cell formatting). You can find a sample stylesheet here.
- Chroma styles:
nbtohtmlinternally uses Chroma for syntax highlighting, which supports various themes. You can find a sample stylesheet here.
Rendering of LaTeX math must be done on the client side. Various libraries exist, KaTeX is a great option. You only need to link to the KaTeX scripts/styles, and LaTeX math will automatically be rendered after your web page has loaded.
Suggestions and contributions are always welcome! Please discuss larger changes via issue before submitting a pull request.