Documentation
¶
Index ¶
- type DiagramRenderer
- 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) PopPad()
- 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) PushPad(width 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) RenderFootnote(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderFootnoteBackLink(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderFootnoteLink(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
- func (r *Renderer) RenderFootnoteList(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) RenderTaskCheckBox(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) 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 WithDiagramRenderer(dr DiagramRenderer) 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 WithTableRenderer(tr TableRenderer) RendererOption
- func WithTheme(theme *chroma.Style) RendererOption
- func WithWordWrap(width int) RendererOption
- type TableRenderContext
- type TableRenderer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DiagramRenderer ¶
A DiagramRenderer converts diagram source code into rendered text. targetWidth is the desired maximum output width in characters (0 = no constraint). Returns an error for unsupported languages, causing fallback to normal code rendering.
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) PushPad ¶
PushPad enables line padding to the given width in the current rendering context. A width of 0 disables padding.
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) RenderFootnote ¶
func (r *Renderer) RenderFootnote(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
RenderFootnote renders an *xast.Footnote node to the given BufWriter as an indented entry prefixed with `[N]:`. The trailing space is supplied by the child paragraph's source leading whitespace, so continuation lines indent by len(marker)+1.
The marker is written with word wrap disabled so that it leaves the buffered-write path before the indent is pushed; otherwise the indent would be applied to the marker's own line.
func (*Renderer) RenderFootnoteBackLink ¶
func (r *Renderer) RenderFootnoteBackLink(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
RenderFootnoteBackLink renders an *xast.FootnoteBackLink. Back-links exist in the AST so HTML can hyperlink back from the footnote body to its reference; the terminal renderer drops them.
func (*Renderer) RenderFootnoteLink ¶
func (r *Renderer) RenderFootnoteLink(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
RenderFootnoteLink renders an *xast.FootnoteLink node as `[N]`, styled like a link.
func (*Renderer) RenderFootnoteList ¶
func (r *Renderer) RenderFootnoteList(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
RenderFootnoteList renders an *xast.FootnoteList node to the given BufWriter. The list opens with a horizontal rule that visually separates the footnote definitions from the body of the document.
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) RenderTaskCheckBox ¶
func (r *Renderer) RenderTaskCheckBox(w util.BufWriter, source []byte, node ast.Node, enter bool) (ast.WalkStatus, error)
RenderTaskCheckBox is a no-op: the checkbox glyph is emitted by RenderListItem in the bullet/number marker slot, so re-rendering it here would double the glyph.
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) 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 WithDiagramRenderer ¶
func WithDiagramRenderer(dr DiagramRenderer) RendererOption
WithDiagramRenderer sets the diagram renderer used to convert diagram code blocks (e.g. mermaid) into rendered text. If the renderer returns an error for a given language, the code block falls back to normal syntax-highlighted rendering.
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 WithTableRenderer ¶
func WithTableRenderer(tr TableRenderer) RendererOption
WithTableRenderer sets the table renderer used to render tables with a custom implementation (e.g. an interactive grid widget). If the renderer returns an error, the built-in static table rendering is used as a fallback.
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.
type TableRenderContext ¶
type TableRenderContext struct {
Table *xast.Table
Source []byte
Width int // available width (wordWrap)
Theme *chroma.Style
Alignments []xast.Alignment
// contains filtered or unexported fields
}
TableRenderContext provides controlled access to the renderer for custom table rendering. Methods mirror the DiagramRenderer integration pattern.
func (*TableRenderContext) ByteOffset ¶
func (ctx *TableRenderContext) ByteOffset() int
ByteOffset returns the current byte offset in rendered output.
func (*TableRenderContext) InsertSpan ¶
func (ctx *TableRenderContext) InsertSpan(node ast.Node, start, end int)
InsertSpan registers a span for an AST node (e.g. links in cells) at the given absolute byte offsets. Used by the callback for navigation support.
func (*TableRenderContext) RenderCell ¶
func (ctx *TableRenderContext) RenderCell(cell ast.Node, width int, rowIndex int) (string, []ast.Node, error)
RenderCell renders a table cell's inline content to a styled string. rowIndex is used to determine the row style (0 = header, odd/even for body rows). Returns rendered content and link nodes found in the cell.
func (*TableRenderContext) WriteString ¶
func (ctx *TableRenderContext) WriteString(s string) (int, error)
WriteString writes content through the renderer's pipeline, tracking byte offsets for span alignment. Word wrap is disabled during table rendering because the custom renderer is responsible for sizing its output to fit within the available width.
type TableRenderer ¶
type TableRenderer func(ctx *TableRenderContext) error
A TableRenderer renders a table using a custom implementation. If the renderer returns an error, the built-in table rendering is used as a fallback.