mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-02 23:17:34 -04:00
Add documentation for a few more types
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user