mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-06 08:57:14 -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
|
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.
|
// nodes.
|
||||||
type Element struct {
|
type Element struct {
|
||||||
Entering string
|
Entering string
|
||||||
|
|||||||
@@ -8,12 +8,15 @@ import (
|
|||||||
"github.com/muesli/reflow/padding"
|
"github.com/muesli/reflow/padding"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// MarginWriter is a Writer that applies indentation and padding around
|
||||||
|
// whatever you write to it.
|
||||||
type MarginWriter struct {
|
type MarginWriter struct {
|
||||||
w io.Writer
|
w io.Writer
|
||||||
pw *padding.Writer
|
pw *padding.Writer
|
||||||
iw *indent.Writer
|
iw *indent.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewMarginWriter returns a new MarginWriter.
|
||||||
func NewMarginWriter(ctx RenderContext, w io.Writer, rules StyleBlock) *MarginWriter {
|
func NewMarginWriter(ctx RenderContext, w io.Writer, rules StyleBlock) *MarginWriter {
|
||||||
bs := ctx.blockStack
|
bs := ctx.blockStack
|
||||||
|
|
||||||
|
|||||||
+6
-5
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/yuin/goldmark/util"
|
"github.com/yuin/goldmark/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Options is used to configure an ANSIRenderer.
|
||||||
type Options struct {
|
type Options struct {
|
||||||
BaseURL string
|
BaseURL string
|
||||||
WordWrap int
|
WordWrap int
|
||||||
@@ -79,17 +80,17 @@ func (r *ANSIRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) {
|
|||||||
reg.Register(astext.KindStrikethrough, r.renderNode)
|
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()))
|
// _, _ = w.Write([]byte(node.Type.String()))
|
||||||
writeTo := io.Writer(w)
|
writeTo := io.Writer(w)
|
||||||
bs := tr.context.blockStack
|
bs := r.context.blockStack
|
||||||
|
|
||||||
// children get rendered by their parent
|
// children get rendered by their parent
|
||||||
if isChild(node) {
|
if isChild(node) {
|
||||||
return ast.WalkContinue, nil
|
return ast.WalkContinue, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
e := tr.NewElement(node, source)
|
e := r.NewElement(node, source)
|
||||||
if entering {
|
if entering {
|
||||||
// everything below the Document element gets rendered into a block buffer
|
// everything below the Document element gets rendered into a block buffer
|
||||||
if bs.Len() > 0 {
|
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))
|
_, _ = writeTo.Write([]byte(e.Entering))
|
||||||
if e.Renderer != nil {
|
if e.Renderer != nil {
|
||||||
err := e.Renderer.Render(writeTo, tr.context)
|
err := e.Renderer.Render(writeTo, r.context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ast.WalkStop, err
|
return ast.WalkStop, err
|
||||||
}
|
}
|
||||||
@@ -116,7 +117,7 @@ func (tr *ANSIRenderer) renderNode(w util.BufWriter, source []byte, node ast.Nod
|
|||||||
}
|
}
|
||||||
|
|
||||||
if e.Finisher != nil {
|
if e.Finisher != nil {
|
||||||
err := e.Finisher.Finish(writeTo, tr.context)
|
err := e.Finisher.Finish(writeTo, r.context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ast.WalkStop, err
|
return ast.WalkStop, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/lucasb-eyer/go-colorful"
|
"github.com/lucasb-eyer/go-colorful"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// StylePrimitive holds all the basic style settings.
|
||||||
type StylePrimitive struct {
|
type StylePrimitive struct {
|
||||||
BlockPrefix string `json:"block_prefix"`
|
BlockPrefix string `json:"block_prefix"`
|
||||||
BlockSuffix string `json:"block_suffix"`
|
BlockSuffix string `json:"block_suffix"`
|
||||||
@@ -23,12 +24,14 @@ type StylePrimitive struct {
|
|||||||
Format string `json:"format"`
|
Format string `json:"format"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StyleTask holds the style settings for a task item.
|
||||||
type StyleTask struct {
|
type StyleTask struct {
|
||||||
StylePrimitive
|
StylePrimitive
|
||||||
Ticked string `json:"ticked"`
|
Ticked string `json:"ticked"`
|
||||||
Unticked string `json:"unticked"`
|
Unticked string `json:"unticked"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StyleBlock holds the basic style settings for block elements.
|
||||||
type StyleBlock struct {
|
type StyleBlock struct {
|
||||||
StylePrimitive
|
StylePrimitive
|
||||||
Indent *uint `json:"indent"`
|
Indent *uint `json:"indent"`
|
||||||
@@ -36,6 +39,7 @@ type StyleBlock struct {
|
|||||||
Margin *uint `json:"margin"`
|
Margin *uint `json:"margin"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StyleCodeBlock holds the style settings for a code block.
|
||||||
type StyleCodeBlock struct {
|
type StyleCodeBlock struct {
|
||||||
StyleBlock
|
StyleBlock
|
||||||
Theme string `json:"theme"`
|
Theme string `json:"theme"`
|
||||||
@@ -74,11 +78,13 @@ type StyleCodeBlock struct {
|
|||||||
} `json:"chroma"`
|
} `json:"chroma"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StyleList holds the style settings for a list.
|
||||||
type StyleList struct {
|
type StyleList struct {
|
||||||
StyleBlock
|
StyleBlock
|
||||||
LevelIndent uint `json:"level_indent"`
|
LevelIndent uint `json:"level_indent"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StyleTable holds the style settings for a table.
|
||||||
type StyleTable struct {
|
type StyleTable struct {
|
||||||
StyleBlock
|
StyleBlock
|
||||||
CenterSeparator *string `json:"center_separator"`
|
CenterSeparator *string `json:"center_separator"`
|
||||||
@@ -86,6 +92,7 @@ type StyleTable struct {
|
|||||||
RowSeparator *string `json:"row_separator"`
|
RowSeparator *string `json:"row_separator"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StyleConfig is used to configure the styling behavior of an ANSIRenderer.
|
||||||
type StyleConfig struct {
|
type StyleConfig struct {
|
||||||
Document StyleBlock `json:"document"`
|
Document StyleBlock `json:"document"`
|
||||||
BlockQuote StyleBlock `json:"block_quote"`
|
BlockQuote StyleBlock `json:"block_quote"`
|
||||||
|
|||||||
@@ -5,12 +5,14 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// StyleWriter is a Writer that applies styling on whatever you write to it.
|
||||||
type StyleWriter struct {
|
type StyleWriter struct {
|
||||||
w io.Writer
|
w io.Writer
|
||||||
buf bytes.Buffer
|
buf bytes.Buffer
|
||||||
rules StylePrimitive
|
rules StylePrimitive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewStyleWriter returns a new StyleWriter.
|
||||||
func NewStyleWriter(ctx RenderContext, w io.Writer, rules StylePrimitive) *StyleWriter {
|
func NewStyleWriter(ctx RenderContext, w io.Writer, rules StylePrimitive) *StyleWriter {
|
||||||
return &StyleWriter{
|
return &StyleWriter{
|
||||||
w: w,
|
w: w,
|
||||||
@@ -22,6 +24,7 @@ func (w *StyleWriter) Write(b []byte) (int, error) {
|
|||||||
return w.buf.Write(b)
|
return w.buf.Write(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close must be called when you're finished writing to a StyleWriter.
|
||||||
func (w *StyleWriter) Close() error {
|
func (w *StyleWriter) Close() error {
|
||||||
renderText(w.w, w.rules, w.buf.String())
|
renderText(w.w, w.rules, w.buf.String())
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -16,12 +16,15 @@ type TableElement struct {
|
|||||||
cell []string
|
cell []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A TableRowElement is used to render a single row in a table.
|
||||||
type TableRowElement struct {
|
type TableRowElement struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A TableHeadElement is used to render a table's head element.
|
||||||
type TableHeadElement struct {
|
type TableHeadElement struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A TableCellElement is used to render a single cell in a row.
|
||||||
type TableCellElement struct {
|
type TableCellElement struct {
|
||||||
Text string
|
Text string
|
||||||
Head bool
|
Head bool
|
||||||
|
|||||||
Reference in New Issue
Block a user