Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/samuelmeuli/nbtohtml
📈 Convert Jupyter Notebook files to HTML
https://github.com/samuelmeuli/nbtohtml
converter jupyter-notebook jupyter-to-html notebook notebook-to-html
Last synced: about 2 months ago
JSON representation
📈 Convert Jupyter Notebook files to HTML
- Host: GitHub
- URL: https://github.com/samuelmeuli/nbtohtml
- Owner: samuelmeuli
- License: mit
- Archived: true
- Created: 2020-03-12T06:57:39.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-04-28T21:07:11.000Z (over 4 years ago)
- Last Synced: 2024-09-22T19:30:59.553Z (about 2 months ago)
- Topics: converter, jupyter-notebook, jupyter-to-html, notebook, notebook-to-html
- Language: Go
- Homepage: https://nbtohtml.samuelmeuli.com
- Size: 239 KB
- Stars: 9
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# nbtohtml
**`nbtohtml` is a Go library and CLI for rendering Jupyter Notebooks as HTML.**
**Advantages over similar libraries** like [`notebook.js`](https://github.com/jsvine/notebookjs) or [`nbviewer.js`](https://github.com/kokes/nbviewer.js):
- 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## Example
→ [Example of a rendered notebook](https://nbtohtml.samuelmeuli.com)
![Screenshot of rendered HTML](./.github/screenshot.png)
## Usage
### As a CLI
#### Pre-compiled
1. Download the latest binary from the [Releases page](https://github.com/samuelmeuli/nbtohtml/releases/latest)
2. Run `./nbtohtml convert /path/to/your/notebook.ipynb` in the directory where you've downloaded the program#### Self-compiled
1. Compile and install the program by running `go get -u github.com/samuelmeuli/nbtohtml/cmd/nbtohtml`
2. Run `nbtohtml convert /path/to/your/notebook.ipynb`### As a library
1. Install `nbtohtml` as a dependency in your Go project: `go get -u github.com/samuelmeuli/nbtohtml`
2. Use the library in your code:```go
notebookHTML := new(bytes.Buffer)
notebookPath := "/path/to/your/notebook.ipynb"
err := nbtohtml.ConvertFile(notebookHTML, notebookPath)
```## Styles
`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](./examples/nbtohtml/notebook.css).
- **Chroma styles**: `nbtohtml` internally uses [Chroma](https://github.com/alecthomas/chroma) for syntax highlighting, which supports [various themes](https://xyproto.github.io/splash/docs). You can find a sample stylesheet [here](./examples/nbtohtml/chroma.css).## LaTeX Math
Rendering of LaTeX math must be done on the client side. Various libraries exist, [KaTeX](https://katex.org) is a great option. You only need to [link to the KaTeX scripts/styles](https://katex.org/docs/browser.html), and LaTeX math will automatically be rendered after your web page has loaded.
## Contributing
Suggestions and contributions are always welcome! Please discuss larger changes via issue before submitting a pull request.