Document BlockStack and make linter happ[y/ier].

This commit is contained in:
Christian Muehlhaeuser
2019-12-25 05:26:18 +01:00
parent a1da1963cb
commit 9157a40ab2
9 changed files with 17 additions and 8 deletions
+9
View File
@@ -8,14 +8,17 @@ import (
// indentation & margin level during the rendering process. // indentation & margin level during the rendering process.
type BlockStack []BlockElement type BlockStack []BlockElement
// Len returns the length of the stack.
func (s *BlockStack) Len() int { func (s *BlockStack) Len() int {
return len(*s) return len(*s)
} }
// Push appends an item to the stack.
func (s *BlockStack) Push(e BlockElement) { func (s *BlockStack) Push(e BlockElement) {
*s = append(*s, e) *s = append(*s, e)
} }
// Pop removes the last item on the stack.
func (s *BlockStack) Pop() { func (s *BlockStack) Pop() {
stack := *s stack := *s
if len(stack) == 0 { if len(stack) == 0 {
@@ -26,6 +29,7 @@ func (s *BlockStack) Pop() {
*s = stack *s = stack
} }
// Indent returns the current indentation level of all elements in the stack.
func (s BlockStack) Indent() uint { func (s BlockStack) Indent() uint {
var i uint var i uint
@@ -39,6 +43,7 @@ func (s BlockStack) Indent() uint {
return i return i
} }
// Margin returns the current margin level of all elements in the stack.
func (s BlockStack) Margin() uint { func (s BlockStack) Margin() uint {
var i uint var i uint
@@ -52,6 +57,7 @@ func (s BlockStack) Margin() uint {
return i return i
} }
// Width returns the available rendering width
func (s BlockStack) Width(ctx RenderContext) uint { func (s BlockStack) Width(ctx RenderContext) uint {
if s.Indent()+s.Margin()*2 > uint(ctx.options.WordWrap) { if s.Indent()+s.Margin()*2 > uint(ctx.options.WordWrap) {
return 0 return 0
@@ -59,6 +65,7 @@ func (s BlockStack) Width(ctx RenderContext) uint {
return uint(ctx.options.WordWrap) - s.Indent() - s.Margin()*2 return uint(ctx.options.WordWrap) - s.Indent() - s.Margin()*2
} }
// Parent returns the current BlockElement's parent.
func (s BlockStack) Parent() BlockElement { func (s BlockStack) Parent() BlockElement {
if len(s) == 1 { if len(s) == 1 {
return BlockElement{ return BlockElement{
@@ -69,6 +76,7 @@ func (s BlockStack) Parent() BlockElement {
return s[len(s)-2] return s[len(s)-2]
} }
// Current returns the current BlockElement.
func (s BlockStack) Current() BlockElement { func (s BlockStack) Current() BlockElement {
if len(s) == 0 { if len(s) == 0 {
return BlockElement{ return BlockElement{
@@ -79,6 +87,7 @@ func (s BlockStack) Current() BlockElement {
return s[len(s)-1] return s[len(s)-1]
} }
// With returns a StylePrimitive that inherits the current BlockElement's style.
func (s BlockStack) With(child StylePrimitive) StylePrimitive { func (s BlockStack) With(child StylePrimitive) StylePrimitive {
sb := StyleBlock{} sb := StyleBlock{}
sb.StylePrimitive = child sb.StylePrimitive = child
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"github.com/muesli/reflow/indent" "github.com/muesli/reflow/indent"
) )
// CodeBlockElements are used to render code blocks. // A CodeBlockElement is used to render code blocks.
type CodeBlockElement struct { type CodeBlockElement struct {
Code string Code string
Language string Language string
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"github.com/muesli/reflow/wordwrap" "github.com/muesli/reflow/wordwrap"
) )
// HeadingElements are used to render headings. // A HeadingElement is used to render headings.
type HeadingElement struct { type HeadingElement struct {
Level int Level int
First bool First bool
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"io" "io"
) )
// ImageElements are used to render images elements. // An ImageElement is used to render images elements.
type ImageElement struct { type ImageElement struct {
Text string Text string
BaseURL string BaseURL string
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"io" "io"
) )
// LinkElements are used to render hyperlinks. // A LinkElement is used to render hyperlinks.
type LinkElement struct { type LinkElement struct {
Text string Text string
BaseURL string BaseURL string
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"strconv" "strconv"
) )
// ItemElements are used to render items inside a list. // An ItemElement is used to render items inside a list.
type ItemElement struct { type ItemElement struct {
Enumeration uint Enumeration uint
} }
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"github.com/muesli/reflow/wordwrap" "github.com/muesli/reflow/wordwrap"
) )
// ParagraphElements are used to render individual paragraphs. // A ParagraphElement is used to render individual paragraphs.
type ParagraphElement struct { type ParagraphElement struct {
First bool First bool
} }
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"github.com/olekukonko/tablewriter" "github.com/olekukonko/tablewriter"
) )
// TableElements are used to render tables. // A TableElement is used to render tables.
type TableElement struct { type TableElement struct {
writer *tablewriter.Table writer *tablewriter.Table
styleWriter *StyleWriter styleWriter *StyleWriter
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"io" "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 { type TaskElement struct {
Checked bool Checked bool
} }