v3

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package v3 provides a decoder for Jupyter Notebooks v1.0, v2.0, and v3.0.

It implements the IPython Notebook v3.0 JSON Schema, which is also suitable for decoding all earlier versions, as there hasn't been any breaking changes to it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code struct {
	Source        common.MultilineString `json:"input"`
	TimesExecuted int                    `json:"prompt_number"`
	Out           []Output               `json:"outputs"`
	Lang          string                 `json:"language"`
}

Code defines the schema for a "code" cell.

func (*Code) ExecutionCount

func (code *Code) ExecutionCount() int

func (*Code) Language

func (code *Code) Language() string

func (*Code) MimeType

func (code *Code) MimeType() string

FIXME: return correct mime type (add a function to common)

func (*Code) Outputs

func (code *Code) Outputs() (cells []schema.Cell)

func (*Code) Text

func (code *Code) Text() []byte

func (*Code) Type

func (code *Code) Type() schema.CellType

type DisplayDataOutput

type DisplayDataOutput struct {
	MimeBundle
	Metadata map[string]interface{} `json:"metadata"`
}

DisplayDataOutput are rich-format outputs generated by running the code in the parent cell.

func (*DisplayDataOutput) Type

func (dd *DisplayDataOutput) Type() schema.CellType

type ErrorOutput

type ErrorOutput struct {
	ExceptionName  string   `json:"ename"`
	ExceptionValue string   `json:"evalue"`
	Traceback      []string `json:"traceback"`
}

ErrorOutput stores the output of a failed code execution.

func (*ErrorOutput) MimeType

func (err *ErrorOutput) MimeType() string

func (*ErrorOutput) Text

func (err *ErrorOutput) Text() (txt []byte)

func (*ErrorOutput) Type

func (err *ErrorOutput) Type() schema.CellType

type ExecuteResultOutput

type ExecuteResultOutput struct {
	DisplayDataOutput
	TimesExecuted int `json:"prompt_number"`
}

ExecuteResultOutput is the result of executing the code in the cell. Its contents are identical to those of DisplayDataOutput with the addition of the execution count.

func (*ExecuteResultOutput) ExecutionCount

func (ex *ExecuteResultOutput) ExecutionCount() int

func (*ExecuteResultOutput) Type

func (ex *ExecuteResultOutput) Type() schema.CellType

type Heading

type Heading struct {
	Markdown
	Level int `json:"level"`
}

Heading is a dedicated cell type which represent a heading in a Jupyter notebook. This type is deprecated in the later versions and the content is stored as markdown instead.

Heading cell behaves exactly like a markdown cell, decorating its source with the appropriate number of heading signs (#).

func (*Heading) Text

func (h *Heading) Text() []byte

type Markdown

type Markdown = common.Markdown

type MimeBundle

type MimeBundle struct {
	PNG        common.MultilineString `json:"png,omitempty"`
	JPEG       common.MultilineString `json:"jpeg,omitempty"`
	HTML       common.MultilineString `json:"html,omitempty"`
	SVG        common.MultilineString `json:"svg,omitempty"`
	Javascript common.MultilineString `json:"javascript,omitempty"`
	JSON       common.MultilineString `json:"json,omitempty"`
	PDF        common.MultilineString `json:"pdf,omitempty"`
	LaTeX      common.MultilineString `json:"latex,omitempty"`
	Txt        common.MultilineString `json:"text,omitempty"`
}

MimeBundle contains rich output data keyed by mime-type.

func (MimeBundle) Data

func (mb MimeBundle) Data(mime string) []byte

Data returns mime-type-specific content if present and a nil slice otherwise.

func (MimeBundle) MimeType

func (mb MimeBundle) MimeType() string

MimeType returns the richer of the mime-types present in the bundle, and falls back to "text/plain" otherwise.

func (MimeBundle) PlainText

func (mb MimeBundle) PlainText() []byte

PlainText returns data for "text/plain" mime-type and a nil slice otherwise.

func (MimeBundle) Text

func (mb MimeBundle) Text() []byte

Text returns data with the richer mime-type.

type Output

type Output struct {
	// contains filtered or unexported fields
}

Outputs unmarshals cell outputs into schema.Cell based on their type.

func (*Output) UnmarshalJSON

func (out *Output) UnmarshalJSON(data []byte) error

type Raw

type Raw = common.Raw

type StreamOutput

type StreamOutput struct {
	// Target can be stdout or stderr.
	Target string                 `json:"stream"`
	Source common.MultilineString `json:"text"`
}

StreamOutput is a plain, text-based output of the executed code. Depending on the stream "target", Type() can report "text/plain" (stdout) or "error" (stderr). The output is often decorated with ANSI-color sequences, which should be handled separately.

func (*StreamOutput) MimeType

func (stream *StreamOutput) MimeType() string

func (*StreamOutput) Text

func (stream *StreamOutput) Text() []byte

func (*StreamOutput) Type

func (stream *StreamOutput) Type() schema.CellType

Jump to

Keyboard shortcuts

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