nbtohtml

package module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2020 License: MIT Imports: 18 Imported by: 0

README

nbtohtml

nbtohtml is a Go library and CLI for rendering Jupyter Notebooks as HTML.

Advantages over similar libraries like notebook.js or 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

Screenshot of rendered HTML

Usage

As a CLI
Pre-compiled
  1. Download the latest binary from the Releases page
  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:
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.
  • Chroma styles: nbtohtml internally uses Chroma for syntax highlighting, which supports various themes. You can find a sample stylesheet here.

LaTeX Math

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.

Contributing

Suggestions and contributions are always welcome! Please discuss larger changes via issue before submitting a pull request.

Documentation

Overview

Package nbtohtml is a library for converting Jupyter Notebook files to HTML.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertFile

func ConvertFile(writer io.Writer, notebookPath string) error

ConvertFile reads the file at the provided path and converts its content (the Jupyter Notebook JSON) to HTML.

For example, the function can be called the following way:

notebookHTML := new(bytes.Buffer)
notebookPath := "/path/to/your/notebook.ipynb"
err := nbtohtml.ConvertFile(notebookHTML, notebookPath)

func ConvertString

func ConvertString(writer io.Writer, notebookString string) error

ConvertString converts the provided Jupyter Notebook JSON string to HTML.

For example, the function can be called the following way:

notebookHTML := new(bytes.Buffer)
notebookString := `{ "cells": ... }`
err := nbtohtml.ConvertString(notebookHTML, notebookString)

Types

This section is empty.

Directories

Path Synopsis
cmd
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL