render

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: MIT Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CellRenderer

type CellRenderer interface {
	// RegisterFuncs registers one or more RenderCellFunc with the passed renderer.
	RegisterFuncs(RenderCellFuncRegisterer)
}

CellRenderer registers a RenderCellFunc for every cell type it supports.

Reminiscent of the Visitor pattern, it allows extending the base renderer to support any number of arbitrary cell types.

type CellWrapper

type CellWrapper interface {
	// Wrap the entire cell block.
	Wrap(io.Writer, schema.Cell, RenderCellFunc) error

	// Wrap input block.
	WrapInput(io.Writer, schema.Cell, RenderCellFunc) error

	// Wrap output block (code cells).
	WrapOutput(io.Writer, schema.Outputter, RenderCellFunc) error
}

CellWrapper renders common wrapping elements for every cell type.

type Option

type Option func(r *renderer)

func WithCellRenderers

func WithCellRenderers(crs ...CellRenderer) Option

WithCellRenderers adds support for other cell types to the base renderer. If a renderer implements CellWrapper, it will be used to wrap input and output cells. Only one cell wrapper can be configured, and so the last implementor will take precedence.

type RenderCellFunc

type RenderCellFunc func(io.Writer, schema.Cell) error

RenderCellFunc writes contents of a specific cell type.

type RenderCellFuncRegisterer

type RenderCellFuncRegisterer interface {
	// Register adds a RenderCellFunc that will be called for cells of this type.
	Register(schema.CellTypeMixed, RenderCellFunc)
}

RenderCellFuncRegisterer is an interface that extendable Renderers should implement.

type Renderer

type Renderer interface {
	// Render writes the contents of the notebook cells it supports.
	//
	// Implementations should not error on cell types, for which no RenderCellFunc is registered.
	// This is expected, as some [RawCells] will be rendered in some output formats and ignored in others.
	//
	// [RawCells]: https://nbformat.readthedocs.io/en/latest/format_description.html#raw-nbconvert-cells
	Render(io.Writer, schema.Notebook) error

	// AddOptions configures the editor after it has been constructured.
	// The renderer's configuration should not change between renders, and so, implementations should
	// ignore options added after the first call to Render().
	AddOptions(...Option)
}

Renderer renders a decoded notebook in the format it implements.

func New

func New(opts ...Option) Renderer

New extends the base renderer with the passed options.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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