renderer

package
v0.0.0-...-66ecaaf Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ImageEncoder

type ImageEncoder func(w io.Writer, image image.Image, r *Renderer) (int, error)

An ImageEncoder converts an image to a binary representation that can be displayed by the target output device.

func ANSIGraphicsEncoder

func ANSIGraphicsEncoder(bg color.Color, ditherMode ansimage.DitheringMode) ImageEncoder

An ANSIGraphicsEncoder encodes images to a Writer using ANSI or ASCII characters.

func KittyGraphicsEncoder

func KittyGraphicsEncoder() ImageEncoder

A KittyGraphicsEncoder encodes image data to a Writer using the kitty graphics protocol.

type NodeSpan

type NodeSpan struct {
	// The byte offset of the start of the span. Inclusive.
	Start int
	// The byte offset of the end of the span. Exclusive.
	End int
	// The node that this span represents.
	Node ast.Node

	// The parent node in the span tree.
	Parent *NodeSpan
	// The next node in a preorder traversal of the span tree.
	Next *NodeSpan
	// The previous node in a preorder traversal of the span tree.
	Prev *NodeSpan
	// The children of this node.
	Children []*NodeSpan
}

A NodeSpan maps from an AST node to its representative span in a rendered document. The NodeSpans for an AST form a tree; the root of the span tree for a rendered document can be accessed using Renderer.SpanTree.

func (*NodeSpan) Contains

func (s *NodeSpan) Contains(offset int) bool

Contains returns true if the given byte offset is contained within this node's span.

type Renderer

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

Renderer is a goldmark renderer that produces Markdown output. Due to information loss in goldmark, its output may not be textually identical to the source that produced the AST to be rendered, but the structure should match.

NodeRenderers that want to override rendering of particular node types should write through the Write* functions provided by Renderer in order to retain proper indentation and prefices inside of lists and block quotes.

func New

func New(options ...RendererOption) *Renderer

New creates a new Renderer with the given options.

func (*Renderer) CloseBlock

func (r *Renderer) CloseBlock(w io.Writer) error

CloseBlock marks the current block as closed.

func (*Renderer) CloseSpan

func (r *Renderer) CloseSpan()

CloseSpan closes the current span.

func (*Renderer) OpenBlock

func (r *Renderer) OpenBlock(w util.BufWriter, source []byte, node ast.Node) error

OpenBlock ensures that each block begins on a new line, and that blank lines are inserted before blocks as indicated by node.HasPreviousBlankLines.

func (*Renderer) OpenSpan

func (r *Renderer) OpenSpan(node ast.Node)

OpenSpan begins a new span associated with the given node.

func (*Renderer) PopPrefix

func (r *Renderer) PopPrefix()

PopPrefix removes the last piece added by a call to PushIndent or PushPrefix from the current line prefix.

func (*Renderer) PopStyle

func (r *Renderer) PopStyle(w io.Writer) error

func (*Renderer) PopWordWrap

func (r *Renderer) PopWordWrap()

PopWordWrap restores the word wrap setting prior to the last call to PushWordWrap.

func (*Renderer) Prefix

func (r *Renderer) Prefix() string

Prefix returns the prefix for the current line, if any.

func (*Renderer) PushIndent

func (r *Renderer) PushIndent(amount int)

PushIndent adds the specified amount of indentation to the current line prefix.

func (*Renderer) PushPrefix

func (r *Renderer) PushPrefix(prefix string)

PushPrefix adds the specified string to the current line prefix.

func (*Renderer) PushStyle

func (r *Renderer) PushStyle(w io.Writer, token chroma.TokenType) error

func (*Renderer) PushWordWrap

func (r *Renderer) PushWordWrap(wrap bool)

PushWordWrap enables or disables word wrapping in the current rendering context.

func (*Renderer) RegisterFuncs

func (r *Renderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer)

RegisterFuncs implements renderer.NodeRenderer.RegisterFuncs.

func (r *Renderer) RenderAutoLink(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderAutoLink renders an *ast.AutoLink node to the given BufWriter.

func (*Renderer) RenderBlockquote

func (r *Renderer) RenderBlockquote(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderBlockquote renders an *ast.Blockquote node to the given BufWriter.

func (*Renderer) RenderCodeBlock

func (r *Renderer) RenderCodeBlock(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderCodeBlock renders an *ast.CodeBlock node to the given BufWriter.

func (*Renderer) RenderCodeSpan

func (r *Renderer) RenderCodeSpan(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderCodeSpan renders an *ast.CodeSpan node to the given BufWriter.

func (*Renderer) RenderDocument

func (r *Renderer) RenderDocument(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderDocument renders an *ast.Document node to the given BufWriter.

func (*Renderer) RenderEmphasis

func (r *Renderer) RenderEmphasis(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderEmphasis renders an *ast.Emphasis node to the given BufWriter.

func (*Renderer) RenderFencedCodeBlock

func (r *Renderer) RenderFencedCodeBlock(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderFencedCodeBlock renders an *ast.FencedCodeBlock node to the given BufWriter.

func (*Renderer) RenderHTMLBlock

func (r *Renderer) RenderHTMLBlock(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderHTMLBlock renders an *ast.HTMLBlock node to the given BufWriter.

func (*Renderer) RenderHeading

func (r *Renderer) RenderHeading(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderHeading renders an *ast.Heading node to the given BufWriter.

func (*Renderer) RenderImage

func (r *Renderer) RenderImage(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderImage renders an *ast.Image node to the given BufWriter.

func (r *Renderer) RenderLink(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderLink renders an *ast.Link node to the given BufWriter.

func (*Renderer) RenderLinkReferenceDefinition

func (r *Renderer) RenderLinkReferenceDefinition(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderLinkReferenceDefinition renders an *ast.LinkReferenceDefinition node to the given BufWriter.

func (*Renderer) RenderList

func (r *Renderer) RenderList(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderList renders an *ast.List node to the given BufWriter.

func (*Renderer) RenderListItem

func (r *Renderer) RenderListItem(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderListItem renders an *ast.ListItem node to the given BufWriter.

func (*Renderer) RenderParagraph

func (r *Renderer) RenderParagraph(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderParagraph renders an *ast.Paragraph node to the given BufWriter.

func (*Renderer) RenderRawHTML

func (r *Renderer) RenderRawHTML(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderRawHTML renders an *ast.RawHTML node to the given BufWriter.

func (*Renderer) RenderString

func (r *Renderer) RenderString(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderString renders an *ast.String node to the given BufWriter.

func (*Renderer) RenderTable

func (r *Renderer) RenderTable(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderTable renders an *xast.Table to the given BufWriter.

func (*Renderer) RenderTableCell

func (r *Renderer) RenderTableCell(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

func (*Renderer) RenderTableHeader

func (r *Renderer) RenderTableHeader(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

func (*Renderer) RenderTableRow

func (r *Renderer) RenderTableRow(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

func (*Renderer) RenderText

func (r *Renderer) RenderText(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderText renders an *ast.Text node to the given BufWriter.

func (*Renderer) RenderTextBlock

func (r *Renderer) RenderTextBlock(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderTextBlock renders an *ast.TextBlock node to the given BufWriter.

func (*Renderer) RenderThematicBreak

func (r *Renderer) RenderThematicBreak(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderThematicBreak renders an *ast.ThematicBreak node to the given BufWriter.

func (*Renderer) RenderWhitespace

func (r *Renderer) RenderWhitespace(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)

RenderWhitespace renders an *ast.Text node to the given BufWriter.

func (*Renderer) SpanTree

func (r *Renderer) SpanTree() *NodeSpan

SpanTree returns the root of the rendered document's span tree. This tree maps AST nodes to their representative text spans in the renderer's output. This method must only be called after a call to RenderDocument.

func (*Renderer) WordWrap

func (r *Renderer) WordWrap() bool

WordWrap returns true if word wrapping is enabled within the current rendering context.

func (*Renderer) Write

func (r *Renderer) Write(w io.Writer, buf []byte) (int, error)

Write writes a slice of bytes to an io.Writer, ensuring that appropriate indentation and prefices are added at the beginning of each line.

func (*Renderer) WriteByte

func (r *Renderer) WriteByte(w io.Writer, c byte) error

WriteByte writes a byte to an io.Writer, ensuring that appropriate indentation and prefices are added at the beginning of each line.

func (*Renderer) WriteRune

func (r *Renderer) WriteRune(w io.Writer, c rune) (int, error)

WriteRune writes a rune to an io.Writer, ensuring that appropriate indentation and prefices are added at the beginning of each line.

func (*Renderer) WriteString

func (r *Renderer) WriteString(w io.Writer, s string) (int, error)

WriteString writes a string to an io.Writer, ensuring that appropriate indentation and prefices are added at the beginning of each line.

func (*Renderer) Writer

func (r *Renderer) Writer(w io.Writer) io.Writer

Writer returns an io.Writer that uses the Renderer's Write method to ensure appropriate indentation and prefices are added at the beginning of each line.

type RendererOption

type RendererOption func(r *Renderer)

A RendererOption represents a configuration option for a Renderer.

func WithGeometry

func WithGeometry(cols, rows, width, height int) RendererOption

WithGeometry sets the geometry of the output.

func WithHyperlinks(on bool) RendererOption

WithHyperlinks enables or disables hyperlink rendering. When hyperlink rendering is enabled, links will be underlined and link destinations will be omitted. The destination of a link can be accessed by looking up the link's node in the span tree using the offset of the link text. Hyperlink rendering is disabled by default.

func WithImageEncoder

func WithImageEncoder(encoder ImageEncoder) RendererOption

WithImageEncoder sets the image encoder used by the renderer. The default image encoder encodes image data using the kitty graphics protocol.

func WithImages

func WithImages(on bool, maxWidth int, contentRoot string) RendererOption

WithImages enables or disables image rendering. When image rendering is enabled, image links will be omitted and image data will be sent inline using the renderer's image encoder. The default image encoder encodes image data using the kitty graphics protocol; the image encoder can be changed using the WithImageEncoder option. Image rendering is disabled by default.

func WithPad

func WithPad(enabled bool) RendererOption

WithPad enables padding each line of output to the wrap width. This option has no effect when word wrapping is disabled.

func WithSoftBreak

func WithSoftBreak(on bool) RendererOption

WithSoftBreak enables or disables soft line breaks. When soft line breaks are enabled, a soft line break in the input will _not_ be rendered as a newline in the output. When soft line breaks are disabled, a soft line break in the input _will_ be rendered as a newline. In general, soft line breaks should be enabled if word wrapping is enabled. Soft line breaks are dsiabled by default.

func WithTheme

func WithTheme(theme *chroma.Style) RendererOption

WithTheme sets the theme used for colorization during rendering. If the theme is nil, output will not be colorized.

func WithWordWrap

func WithWordWrap(width int) RendererOption

WithWordWrap enables word wrapping at the desired width. A width of zero disables wrapping. Words inside code spans or code blocks will not be subject to wrapping. Word wrapping is disabled by default.

Jump to

Keyboard shortcuts

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