Document public types and methods

This commit is contained in:
Christian Muehlhaeuser
2019-12-25 05:19:33 +01:00
parent 9805957441
commit a1da1963cb
14 changed files with 24 additions and 1 deletions
+1
View File
@@ -13,6 +13,7 @@ import (
"github.com/lucasb-eyer/go-colorful"
)
// BaseElement renders a styled primitive element.
type BaseElement struct {
Token string
Prefix string
+3
View File
@@ -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
+2
View File
@@ -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 {
+1
View File
@@ -10,6 +10,7 @@ import (
"github.com/muesli/reflow/indent"
)
// CodeBlockElements are used to render code blocks.
type CodeBlockElement struct {
Code string
Language string
+3
View File
@@ -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 {
+5
View File
@@ -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())
+1
View File
@@ -9,6 +9,7 @@ import (
"github.com/muesli/reflow/wordwrap"
)
// HeadingElements are used to render headings.
type HeadingElement struct {
Level int
First bool
+1
View File
@@ -4,6 +4,7 @@ import (
"io"
)
// ImageElements are used to render images elements.
type ImageElement struct {
Text string
BaseURL string
+1
View File
@@ -4,6 +4,7 @@ import (
"io"
)
// LinkElements are used to render hyperlinks.
type LinkElement struct {
Text string
BaseURL string
+1
View File
@@ -5,6 +5,7 @@ import (
"strconv"
)
// ItemElements are used to render items inside a list.
type ItemElement struct {
Enumeration uint
}
+1
View File
@@ -8,6 +8,7 @@ import (
"github.com/muesli/reflow/wordwrap"
)
// ParagraphElements are used to render individual paragraphs.
type ParagraphElement struct {
First bool
}
+2 -1
View File
@@ -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),
+1
View File
@@ -8,6 +8,7 @@ import (
"github.com/olekukonko/tablewriter"
)
// TableElements are used to render tables.
type TableElement struct {
writer *tablewriter.Table
styleWriter *StyleWriter
+1
View File
@@ -4,6 +4,7 @@ import (
"io"
)
// TaskElements are used to render tasks inside a todo-list.
type TaskElement struct {
Checked bool
}