Add documentation for a few more types

This commit is contained in:
Christian Muehlhaeuser
2019-12-25 05:40:28 +01:00
parent 9157a40ab2
commit 56af24c72d
6 changed files with 23 additions and 6 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ type ElementFinisher interface {
Finish(w io.Writer, ctx RenderContext) error
}
// Elements are used to instruct glamour how to render individual markdown
// An Element is used to instruct the renderer how to handle individual markdown
// nodes.
type Element struct {
Entering string
+3
View File
@@ -8,12 +8,15 @@ import (
"github.com/muesli/reflow/padding"
)
// MarginWriter is a Writer that applies indentation and padding around
// whatever you write to it.
type MarginWriter struct {
w io.Writer
pw *padding.Writer
iw *indent.Writer
}
// NewMarginWriter returns a new MarginWriter.
func NewMarginWriter(ctx RenderContext, w io.Writer, rules StyleBlock) *MarginWriter {
bs := ctx.blockStack
+6 -5
View File
@@ -12,6 +12,7 @@ import (
"github.com/yuin/goldmark/util"
)
// Options is used to configure an ANSIRenderer.
type Options struct {
BaseURL string
WordWrap int
@@ -79,17 +80,17 @@ func (r *ANSIRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) {
reg.Register(astext.KindStrikethrough, r.renderNode)
}
func (tr *ANSIRenderer) renderNode(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
func (r *ANSIRenderer) renderNode(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
// _, _ = w.Write([]byte(node.Type.String()))
writeTo := io.Writer(w)
bs := tr.context.blockStack
bs := r.context.blockStack
// children get rendered by their parent
if isChild(node) {
return ast.WalkContinue, nil
}
e := tr.NewElement(node, source)
e := r.NewElement(node, source)
if entering {
// everything below the Document element gets rendered into a block buffer
if bs.Len() > 0 {
@@ -98,7 +99,7 @@ func (tr *ANSIRenderer) renderNode(w util.BufWriter, source []byte, node ast.Nod
_, _ = writeTo.Write([]byte(e.Entering))
if e.Renderer != nil {
err := e.Renderer.Render(writeTo, tr.context)
err := e.Renderer.Render(writeTo, r.context)
if err != nil {
return ast.WalkStop, err
}
@@ -116,7 +117,7 @@ func (tr *ANSIRenderer) renderNode(w util.BufWriter, source []byte, node ast.Nod
}
if e.Finisher != nil {
err := e.Finisher.Finish(writeTo, tr.context)
err := e.Finisher.Finish(writeTo, r.context)
if err != nil {
return ast.WalkStop, err
}
+7
View File
@@ -4,6 +4,7 @@ import (
"github.com/lucasb-eyer/go-colorful"
)
// StylePrimitive holds all the basic style settings.
type StylePrimitive struct {
BlockPrefix string `json:"block_prefix"`
BlockSuffix string `json:"block_suffix"`
@@ -23,12 +24,14 @@ type StylePrimitive struct {
Format string `json:"format"`
}
// StyleTask holds the style settings for a task item.
type StyleTask struct {
StylePrimitive
Ticked string `json:"ticked"`
Unticked string `json:"unticked"`
}
// StyleBlock holds the basic style settings for block elements.
type StyleBlock struct {
StylePrimitive
Indent *uint `json:"indent"`
@@ -36,6 +39,7 @@ type StyleBlock struct {
Margin *uint `json:"margin"`
}
// StyleCodeBlock holds the style settings for a code block.
type StyleCodeBlock struct {
StyleBlock
Theme string `json:"theme"`
@@ -74,11 +78,13 @@ type StyleCodeBlock struct {
} `json:"chroma"`
}
// StyleList holds the style settings for a list.
type StyleList struct {
StyleBlock
LevelIndent uint `json:"level_indent"`
}
// StyleTable holds the style settings for a table.
type StyleTable struct {
StyleBlock
CenterSeparator *string `json:"center_separator"`
@@ -86,6 +92,7 @@ type StyleTable struct {
RowSeparator *string `json:"row_separator"`
}
// StyleConfig is used to configure the styling behavior of an ANSIRenderer.
type StyleConfig struct {
Document StyleBlock `json:"document"`
BlockQuote StyleBlock `json:"block_quote"`
+3
View File
@@ -5,12 +5,14 @@ import (
"io"
)
// StyleWriter is a Writer that applies styling on whatever you write to it.
type StyleWriter struct {
w io.Writer
buf bytes.Buffer
rules StylePrimitive
}
// NewStyleWriter returns a new StyleWriter.
func NewStyleWriter(ctx RenderContext, w io.Writer, rules StylePrimitive) *StyleWriter {
return &StyleWriter{
w: w,
@@ -22,6 +24,7 @@ func (w *StyleWriter) Write(b []byte) (int, error) {
return w.buf.Write(b)
}
// Close must be called when you're finished writing to a StyleWriter.
func (w *StyleWriter) Close() error {
renderText(w.w, w.rules, w.buf.String())
return nil
+3
View File
@@ -16,12 +16,15 @@ type TableElement struct {
cell []string
}
// A TableRowElement is used to render a single row in a table.
type TableRowElement struct {
}
// A TableHeadElement is used to render a table's head element.
type TableHeadElement struct {
}
// A TableCellElement is used to render a single cell in a row.
type TableCellElement struct {
Text string
Head bool