mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-06 00:47:15 -04:00
Document public types and methods
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/lucasb-eyer/go-colorful"
|
"github.com/lucasb-eyer/go-colorful"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// BaseElement renders a styled primitive element.
|
||||||
type BaseElement struct {
|
type BaseElement struct {
|
||||||
Token string
|
Token string
|
||||||
Prefix string
|
Prefix string
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import (
|
|||||||
"github.com/muesli/reflow/wordwrap"
|
"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 {
|
type BlockElement struct {
|
||||||
Block *bytes.Buffer
|
Block *bytes.Buffer
|
||||||
Style StyleBlock
|
Style StyleBlock
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// BlockStack is a stack of block elements, used to calculate the current
|
||||||
|
// indentation & margin level during the rendering process.
|
||||||
type BlockStack []BlockElement
|
type BlockStack []BlockElement
|
||||||
|
|
||||||
func (s *BlockStack) Len() int {
|
func (s *BlockStack) Len() int {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/muesli/reflow/indent"
|
"github.com/muesli/reflow/indent"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// CodeBlockElements are used to render code blocks.
|
||||||
type CodeBlockElement struct {
|
type CodeBlockElement struct {
|
||||||
Code string
|
Code string
|
||||||
Language string
|
Language string
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/microcosm-cc/bluemonday"
|
"github.com/microcosm-cc/bluemonday"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RenderContext holds the current rendering options and state.
|
||||||
type RenderContext struct {
|
type RenderContext struct {
|
||||||
options Options
|
options Options
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ type RenderContext struct {
|
|||||||
stripper *bluemonday.Policy
|
stripper *bluemonday.Policy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewRenderContext returns a new RenderContext.
|
||||||
func NewRenderContext(options Options) RenderContext {
|
func NewRenderContext(options Options) RenderContext {
|
||||||
return RenderContext{
|
return RenderContext{
|
||||||
options: options,
|
options: options,
|
||||||
@@ -25,6 +27,7 @@ func NewRenderContext(options Options) RenderContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SanitizeHTML sanitizes HTML content.
|
||||||
func (ctx RenderContext) SanitizeHTML(s string, trimSpaces bool) string {
|
func (ctx RenderContext) SanitizeHTML(s string, trimSpaces bool) string {
|
||||||
s = ctx.stripper.Sanitize(s)
|
s = ctx.stripper.Sanitize(s)
|
||||||
if trimSpaces {
|
if trimSpaces {
|
||||||
|
|||||||
@@ -10,14 +10,18 @@ import (
|
|||||||
astext "github.com/yuin/goldmark/extension/ast"
|
astext "github.com/yuin/goldmark/extension/ast"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ElementRenderer is called when entering a markdown node.
|
||||||
type ElementRenderer interface {
|
type ElementRenderer interface {
|
||||||
Render(w io.Writer, ctx RenderContext) error
|
Render(w io.Writer, ctx RenderContext) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ElementFinisher is called when leaving a markdown node.
|
||||||
type ElementFinisher interface {
|
type ElementFinisher interface {
|
||||||
Finish(w io.Writer, ctx RenderContext) error
|
Finish(w io.Writer, ctx RenderContext) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Elements are used to instruct glamour how to render individual markdown
|
||||||
|
// nodes.
|
||||||
type Element struct {
|
type Element struct {
|
||||||
Entering string
|
Entering string
|
||||||
Exiting string
|
Exiting string
|
||||||
@@ -25,6 +29,7 @@ type Element struct {
|
|||||||
Finisher ElementFinisher
|
Finisher ElementFinisher
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewElement returns the appropriate render Element for a given node.
|
||||||
func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element {
|
func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element {
|
||||||
ctx := tr.context
|
ctx := tr.context
|
||||||
// fmt.Print(strings.Repeat(" ", ctx.blockStack.Len()), node.Type(), node.Kind())
|
// fmt.Print(strings.Repeat(" ", ctx.blockStack.Len()), node.Type(), node.Kind())
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/muesli/reflow/wordwrap"
|
"github.com/muesli/reflow/wordwrap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// HeadingElements are used to render headings.
|
||||||
type HeadingElement struct {
|
type HeadingElement struct {
|
||||||
Level int
|
Level int
|
||||||
First bool
|
First bool
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ImageElements are used to render images elements.
|
||||||
type ImageElement struct {
|
type ImageElement struct {
|
||||||
Text string
|
Text string
|
||||||
BaseURL string
|
BaseURL string
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// LinkElements are used to render hyperlinks.
|
||||||
type LinkElement struct {
|
type LinkElement struct {
|
||||||
Text string
|
Text string
|
||||||
BaseURL string
|
BaseURL string
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ItemElements are used to render items inside a list.
|
||||||
type ItemElement struct {
|
type ItemElement struct {
|
||||||
Enumeration uint
|
Enumeration uint
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/muesli/reflow/wordwrap"
|
"github.com/muesli/reflow/wordwrap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ParagraphElements are used to render individual paragraphs.
|
||||||
type ParagraphElement struct {
|
type ParagraphElement struct {
|
||||||
First bool
|
First bool
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -18,11 +18,12 @@ type Options struct {
|
|||||||
Styles StyleConfig
|
Styles StyleConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ANSIRenderer renders markdown content as ANSI escaped sequences.
|
||||||
type ANSIRenderer struct {
|
type ANSIRenderer struct {
|
||||||
context RenderContext
|
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 {
|
func NewRenderer(options Options) *ANSIRenderer {
|
||||||
return &ANSIRenderer{
|
return &ANSIRenderer{
|
||||||
context: NewRenderContext(options),
|
context: NewRenderContext(options),
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/olekukonko/tablewriter"
|
"github.com/olekukonko/tablewriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TableElements are used to render tables.
|
||||||
type TableElement struct {
|
type TableElement struct {
|
||||||
writer *tablewriter.Table
|
writer *tablewriter.Table
|
||||||
styleWriter *StyleWriter
|
styleWriter *StyleWriter
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TaskElements are used to render tasks inside a todo-list.
|
||||||
type TaskElement struct {
|
type TaskElement struct {
|
||||||
Checked bool
|
Checked bool
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user