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.
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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
}