Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmeuli committed Mar 18, 2020
1 parent d310892 commit 871d4f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@
#### 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

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
notebookPath := "path/to/your/notebook.ipynb"
notebookHTML := new(bytes.Buffer)
notebookPath := "/path/to/your/notebook.ipynb"
err := nbtohtml.ConvertFile(notebookHTML, notebookPath)
```

Expand Down
13 changes: 13 additions & 0 deletions convert.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package nbtohtml is a library for converting Jupyter Notebook files to HTML.
package nbtohtml

import (
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 871d4f0

Please sign in to comment.