diff --git a/README.md b/README.md index 3723cf0..17abac1 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,12 @@ #### 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 +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` +2. Run `nbtohtml convert /path/to/your/notebook.ipynb` ### As a library @@ -35,8 +35,8 @@ 2. Use the library in your code: ```go -notebookPath := "path/to/your/notebook.ipynb" notebookHTML := new(bytes.Buffer) +notebookPath := "/path/to/your/notebook.ipynb" err := nbtohtml.ConvertFile(notebookHTML, notebookPath) ``` diff --git a/convert.go b/convert.go index df390ae..139a47f 100644 --- a/convert.go +++ b/convert.go @@ -1,3 +1,4 @@ +// Package nbtohtml is a library for converting Jupyter Notebook files to HTML. package nbtohtml import ( @@ -187,6 +188,12 @@ func convertOutput(output output) template.HTML { // 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 ConvertFile(writer io.Writer, notebookPath string) error { // Read file fileContent, err := ioutil.ReadFile(notebookPath) @@ -199,6 +206,12 @@ func ConvertFile(writer io.Writer, notebookPath 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) func ConvertString(writer io.Writer, notebookString string) error { notebook, err := parseNotebook(notebookString) if err != nil {