Documentation ¶
Index ¶
- type ImageEncoder
- type NodeSpan
- type Renderer
- func (r *Renderer) CloseBlock(w io.Writer) error
- func (r *Renderer) CloseSpan()
- func (r *Renderer) OpenBlock(w util.BufWriter, source []byte, node ast.Node) error
- func (r *Renderer) OpenSpan(node ast.Node)
- func (r *Renderer) PopPrefix()
- func (r *Renderer) PopStyle(w io.Writer) error
- func (r *Renderer) PopWordWrap()
- func (r *Renderer) Prefix() string
- func (r *Renderer) PushIndent(amount int)
- func (r *Renderer) PushPrefix(prefix string)
- func (r *Renderer) PushStyle(w io.Writer, token chroma.TokenType) error
- func (r *Renderer) PushWordWrap(wrap bool)
- func (r *Renderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer)
- func (r *Renderer) RenderAutoLink(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderBlockquote(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderCodeBlock(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderCodeSpan(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderDocument(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderEmphasis(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderFencedCodeBlock(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderHTMLBlock(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderHeading(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderImage(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderLink(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderLinkReferenceDefinition(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderList(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderListItem(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderParagraph(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderRawHTML(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderString(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderTable(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderTableCell(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderTableHeader(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderTableRow(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderText(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderTextBlock(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderThematicBreak(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderWhitespace(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) SpanTree() *NodeSpan
- func (r *Renderer) WordWrap() bool
- func (r *Renderer) Write(w io.Writer, buf []byte) (int, error)
- func (r *Renderer) WriteByte(w io.Writer, c byte) error
- func (r *Renderer) WriteRune(w io.Writer, c rune) (int, error)
- func (r *Renderer) WriteString(w io.Writer, s string) (int, error)
- func (r *Renderer) Writer(w io.Writer) io.Writer
- type RendererOption
- func WithGeometry(cols, rows, width, height int) RendererOption
- func WithHyperlinks(on bool) RendererOption
- func WithImageEncoder(encoder ImageEncoder) RendererOption
- func WithImages(on bool, maxWidth int, contentRoot string) RendererOption
- func WithPad(enabled bool) RendererOption
- func WithSoftBreak(on bool) RendererOption
- func WithTheme(theme *chroma.Style) RendererOption
- func WithWordWrap(width int) RendererOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ImageEncoder ¶
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.
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 ¶
CloseBlock marks the current block as closed.
func (*Renderer) OpenBlock ¶
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) 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) PopWordWrap ¶
func (r *Renderer) PopWordWrap()
PopWordWrap restores the word wrap setting prior to the last call to PushWordWrap.
func (*Renderer) PushIndent ¶
PushIndent adds the specified amount of indentation to the current line prefix.
func (*Renderer) PushPrefix ¶
PushPrefix adds the specified string to the current line prefix.
func (*Renderer) PushWordWrap ¶
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 (*Renderer) RenderAutoLink ¶
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 (*Renderer) RenderLink ¶
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 (*Renderer) RenderTableHeader ¶
func (*Renderer) RenderTableRow ¶
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 ¶
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 ¶
WordWrap returns true if word wrapping is enabled within the current rendering context.
func (*Renderer) Write ¶
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 ¶
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 ¶
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 ¶
WriteString writes a string to an io.Writer, ensuring that 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 ¶
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.