From 9157a40ab27a697c1d12cde857800bf78248bf26 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 25 Dec 2019 05:26:13 +0100 Subject: [PATCH] Document BlockStack and make linter happ[y/ier]. --- ansi/blockstack.go | 9 +++++++++ ansi/codeblock.go | 2 +- ansi/heading.go | 2 +- ansi/image.go | 2 +- ansi/link.go | 2 +- ansi/listitem.go | 2 +- ansi/paragraph.go | 2 +- ansi/table.go | 2 +- ansi/task.go | 2 +- 9 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ansi/blockstack.go b/ansi/blockstack.go index e4ea2c0..0ce8df1 100644 --- a/ansi/blockstack.go +++ b/ansi/blockstack.go @@ -8,14 +8,17 @@ import ( // indentation & margin level during the rendering process. type BlockStack []BlockElement +// Len returns the length of the stack. func (s *BlockStack) Len() int { return len(*s) } +// Push appends an item to the stack. func (s *BlockStack) Push(e BlockElement) { *s = append(*s, e) } +// Pop removes the last item on the stack. func (s *BlockStack) Pop() { stack := *s if len(stack) == 0 { @@ -26,6 +29,7 @@ func (s *BlockStack) Pop() { *s = stack } +// Indent returns the current indentation level of all elements in the stack. func (s BlockStack) Indent() uint { var i uint @@ -39,6 +43,7 @@ func (s BlockStack) Indent() uint { return i } +// Margin returns the current margin level of all elements in the stack. func (s BlockStack) Margin() uint { var i uint @@ -52,6 +57,7 @@ func (s BlockStack) Margin() uint { return i } +// Width returns the available rendering width func (s BlockStack) Width(ctx RenderContext) uint { if s.Indent()+s.Margin()*2 > uint(ctx.options.WordWrap) { return 0 @@ -59,6 +65,7 @@ func (s BlockStack) Width(ctx RenderContext) uint { return uint(ctx.options.WordWrap) - s.Indent() - s.Margin()*2 } +// Parent returns the current BlockElement's parent. func (s BlockStack) Parent() BlockElement { if len(s) == 1 { return BlockElement{ @@ -69,6 +76,7 @@ func (s BlockStack) Parent() BlockElement { return s[len(s)-2] } +// Current returns the current BlockElement. func (s BlockStack) Current() BlockElement { if len(s) == 0 { return BlockElement{ @@ -79,6 +87,7 @@ func (s BlockStack) Current() BlockElement { return s[len(s)-1] } +// With returns a StylePrimitive that inherits the current BlockElement's style. func (s BlockStack) With(child StylePrimitive) StylePrimitive { sb := StyleBlock{} sb.StylePrimitive = child diff --git a/ansi/codeblock.go b/ansi/codeblock.go index 8344091..9e2d91f 100644 --- a/ansi/codeblock.go +++ b/ansi/codeblock.go @@ -10,7 +10,7 @@ import ( "github.com/muesli/reflow/indent" ) -// CodeBlockElements are used to render code blocks. +// A CodeBlockElement is used to render code blocks. type CodeBlockElement struct { Code string Language string diff --git a/ansi/heading.go b/ansi/heading.go index 7d8e5ad..a6f5660 100644 --- a/ansi/heading.go +++ b/ansi/heading.go @@ -9,7 +9,7 @@ import ( "github.com/muesli/reflow/wordwrap" ) -// HeadingElements are used to render headings. +// A HeadingElement is used to render headings. type HeadingElement struct { Level int First bool diff --git a/ansi/image.go b/ansi/image.go index a1104d3..f5edfaf 100644 --- a/ansi/image.go +++ b/ansi/image.go @@ -4,7 +4,7 @@ import ( "io" ) -// ImageElements are used to render images elements. +// An ImageElement is used to render images elements. type ImageElement struct { Text string BaseURL string diff --git a/ansi/link.go b/ansi/link.go index ad0e347..720896e 100644 --- a/ansi/link.go +++ b/ansi/link.go @@ -4,7 +4,7 @@ import ( "io" ) -// LinkElements are used to render hyperlinks. +// A LinkElement is used to render hyperlinks. type LinkElement struct { Text string BaseURL string diff --git a/ansi/listitem.go b/ansi/listitem.go index c47ac80..a64b10d 100644 --- a/ansi/listitem.go +++ b/ansi/listitem.go @@ -5,7 +5,7 @@ import ( "strconv" ) -// ItemElements are used to render items inside a list. +// An ItemElement is used to render items inside a list. type ItemElement struct { Enumeration uint } diff --git a/ansi/paragraph.go b/ansi/paragraph.go index d08b08d..ed7f91d 100644 --- a/ansi/paragraph.go +++ b/ansi/paragraph.go @@ -8,7 +8,7 @@ import ( "github.com/muesli/reflow/wordwrap" ) -// ParagraphElements are used to render individual paragraphs. +// A ParagraphElement is used to render individual paragraphs. type ParagraphElement struct { First bool } diff --git a/ansi/table.go b/ansi/table.go index 31bfc5c..1c792c0 100644 --- a/ansi/table.go +++ b/ansi/table.go @@ -8,7 +8,7 @@ import ( "github.com/olekukonko/tablewriter" ) -// TableElements are used to render tables. +// A TableElement is used to render tables. type TableElement struct { writer *tablewriter.Table styleWriter *StyleWriter diff --git a/ansi/task.go b/ansi/task.go index bb88ae8..468c8fa 100644 --- a/ansi/task.go +++ b/ansi/task.go @@ -4,7 +4,7 @@ import ( "io" ) -// TaskElements are used to render tasks inside a todo-list. +// A TaskElement is used to render tasks inside a todo-list. type TaskElement struct { Checked bool }