diff --git a/ansi/baseelement.go b/ansi/baseelement.go index ad1ed25..55d9f83 100644 --- a/ansi/baseelement.go +++ b/ansi/baseelement.go @@ -13,6 +13,7 @@ import ( "github.com/lucasb-eyer/go-colorful" ) +// BaseElement renders a styled primitive element. type BaseElement struct { Token string Prefix string diff --git a/ansi/blockelement.go b/ansi/blockelement.go index 5b46d6c..ed5659a 100644 --- a/ansi/blockelement.go +++ b/ansi/blockelement.go @@ -7,6 +7,9 @@ import ( "github.com/muesli/reflow/wordwrap" ) +// BlockElement provides a render buffer for children of a block element. +// After all children have been rendered into it, it applies indentation and +// margins around them and writes everything to the parent rendering buffer. type BlockElement struct { Block *bytes.Buffer Style StyleBlock diff --git a/ansi/blockstack.go b/ansi/blockstack.go index 3663988..e4ea2c0 100644 --- a/ansi/blockstack.go +++ b/ansi/blockstack.go @@ -4,6 +4,8 @@ import ( "bytes" ) +// BlockStack is a stack of block elements, used to calculate the current +// indentation & margin level during the rendering process. type BlockStack []BlockElement func (s *BlockStack) Len() int { diff --git a/ansi/codeblock.go b/ansi/codeblock.go index b00a07e..8344091 100644 --- a/ansi/codeblock.go +++ b/ansi/codeblock.go @@ -10,6 +10,7 @@ import ( "github.com/muesli/reflow/indent" ) +// CodeBlockElements are used to render code blocks. type CodeBlockElement struct { Code string Language string diff --git a/ansi/context.go b/ansi/context.go index 3610a6e..ee3c2eb 100644 --- a/ansi/context.go +++ b/ansi/context.go @@ -7,6 +7,7 @@ import ( "github.com/microcosm-cc/bluemonday" ) +// RenderContext holds the current rendering options and state. type RenderContext struct { options Options @@ -16,6 +17,7 @@ type RenderContext struct { stripper *bluemonday.Policy } +// NewRenderContext returns a new RenderContext. func NewRenderContext(options Options) RenderContext { return RenderContext{ options: options, @@ -25,6 +27,7 @@ func NewRenderContext(options Options) RenderContext { } } +// SanitizeHTML sanitizes HTML content. func (ctx RenderContext) SanitizeHTML(s string, trimSpaces bool) string { s = ctx.stripper.Sanitize(s) if trimSpaces { diff --git a/ansi/elements.go b/ansi/elements.go index 8da938d..108d1ac 100644 --- a/ansi/elements.go +++ b/ansi/elements.go @@ -10,14 +10,18 @@ import ( astext "github.com/yuin/goldmark/extension/ast" ) +// ElementRenderer is called when entering a markdown node. type ElementRenderer interface { Render(w io.Writer, ctx RenderContext) error } +// ElementFinisher is called when leaving a markdown node. type ElementFinisher interface { Finish(w io.Writer, ctx RenderContext) error } +// Elements are used to instruct glamour how to render individual markdown +// nodes. type Element struct { Entering string Exiting string @@ -25,6 +29,7 @@ type Element struct { Finisher ElementFinisher } +// NewElement returns the appropriate render Element for a given node. func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element { ctx := tr.context // fmt.Print(strings.Repeat(" ", ctx.blockStack.Len()), node.Type(), node.Kind()) diff --git a/ansi/heading.go b/ansi/heading.go index 919f5a5..7d8e5ad 100644 --- a/ansi/heading.go +++ b/ansi/heading.go @@ -9,6 +9,7 @@ import ( "github.com/muesli/reflow/wordwrap" ) +// HeadingElements are used to render headings. type HeadingElement struct { Level int First bool diff --git a/ansi/image.go b/ansi/image.go index a4bb665..a1104d3 100644 --- a/ansi/image.go +++ b/ansi/image.go @@ -4,6 +4,7 @@ import ( "io" ) +// ImageElements are used to render images elements. type ImageElement struct { Text string BaseURL string diff --git a/ansi/link.go b/ansi/link.go index 02f3635..ad0e347 100644 --- a/ansi/link.go +++ b/ansi/link.go @@ -4,6 +4,7 @@ import ( "io" ) +// LinkElements are used to render hyperlinks. type LinkElement struct { Text string BaseURL string diff --git a/ansi/listitem.go b/ansi/listitem.go index 8ef8622..c47ac80 100644 --- a/ansi/listitem.go +++ b/ansi/listitem.go @@ -5,6 +5,7 @@ import ( "strconv" ) +// ItemElements are used to render items inside a list. type ItemElement struct { Enumeration uint } diff --git a/ansi/paragraph.go b/ansi/paragraph.go index 5cd134e..d08b08d 100644 --- a/ansi/paragraph.go +++ b/ansi/paragraph.go @@ -8,6 +8,7 @@ import ( "github.com/muesli/reflow/wordwrap" ) +// ParagraphElements are used to render individual paragraphs. type ParagraphElement struct { First bool } diff --git a/ansi/renderer.go b/ansi/renderer.go index 2d698ca..4656fd3 100644 --- a/ansi/renderer.go +++ b/ansi/renderer.go @@ -18,11 +18,12 @@ type Options struct { Styles StyleConfig } +// ANSIRenderer renders markdown content as ANSI escaped sequences. type ANSIRenderer struct { context RenderContext } -// NewANSIRenderer returns a new ANSIRenderer with style and options set. +// NewRenderer returns a new ANSIRenderer with style and options set. func NewRenderer(options Options) *ANSIRenderer { return &ANSIRenderer{ context: NewRenderContext(options), diff --git a/ansi/table.go b/ansi/table.go index 0cc49be..31bfc5c 100644 --- a/ansi/table.go +++ b/ansi/table.go @@ -8,6 +8,7 @@ import ( "github.com/olekukonko/tablewriter" ) +// TableElements are used to render tables. type TableElement struct { writer *tablewriter.Table styleWriter *StyleWriter diff --git a/ansi/task.go b/ansi/task.go index 327c3b2..bb88ae8 100644 --- a/ansi/task.go +++ b/ansi/task.go @@ -4,6 +4,7 @@ import ( "io" ) +// TaskElements are used to render tasks inside a todo-list. type TaskElement struct { Checked bool }