mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-08-28 04:46:29 -04:00
Document public types and methods
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/lucasb-eyer/go-colorful"
|
||||
)
|
||||
|
||||
// BaseElement renders a styled primitive element.
|
||||
type BaseElement struct {
|
||||
Token string
|
||||
Prefix string
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/muesli/reflow/indent"
|
||||
)
|
||||
|
||||
// CodeBlockElements are used to render code blocks.
|
||||
type CodeBlockElement struct {
|
||||
Code string
|
||||
Language string
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/muesli/reflow/wordwrap"
|
||||
)
|
||||
|
||||
// HeadingElements are used to render headings.
|
||||
type HeadingElement struct {
|
||||
Level int
|
||||
First bool
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"io"
|
||||
)
|
||||
|
||||
// ImageElements are used to render images elements.
|
||||
type ImageElement struct {
|
||||
Text string
|
||||
BaseURL string
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"io"
|
||||
)
|
||||
|
||||
// LinkElements are used to render hyperlinks.
|
||||
type LinkElement struct {
|
||||
Text string
|
||||
BaseURL string
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// ItemElements are used to render items inside a list.
|
||||
type ItemElement struct {
|
||||
Enumeration uint
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/muesli/reflow/wordwrap"
|
||||
)
|
||||
|
||||
// ParagraphElements are used to render individual paragraphs.
|
||||
type ParagraphElement struct {
|
||||
First bool
|
||||
}
|
||||
|
||||
+2
-1
@@ -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),
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
|
||||
// TableElements are used to render tables.
|
||||
type TableElement struct {
|
||||
writer *tablewriter.Table
|
||||
styleWriter *StyleWriter
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"io"
|
||||
)
|
||||
|
||||
// TaskElements are used to render tasks inside a todo-list.
|
||||
type TaskElement struct {
|
||||
Checked bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user