mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-06 00:47:15 -04:00
Render tables in given style
This commit is contained in:
+13
-9
@@ -9,10 +9,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type TableElement struct {
|
type TableElement struct {
|
||||||
writer *tablewriter.Table
|
writer *tablewriter.Table
|
||||||
indentWriter io.Writer
|
styleWriter *StyleWriter
|
||||||
header []string
|
header []string
|
||||||
cell []string
|
cell []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type TableRowElement struct {
|
type TableRowElement struct {
|
||||||
@@ -39,7 +39,7 @@ func (e *TableElement) Render(w io.Writer, ctx RenderContext) error {
|
|||||||
margin = *rules.Margin
|
margin = *rules.Margin
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.table.indentWriter = &indent.Writer{
|
iw := &indent.Writer{
|
||||||
Indent: indentation + margin,
|
Indent: indentation + margin,
|
||||||
IndentFunc: func(wr io.Writer) {
|
IndentFunc: func(wr io.Writer) {
|
||||||
renderText(w, bs.Current().Style.StylePrimitive, " ")
|
renderText(w, bs.Current().Style.StylePrimitive, " ")
|
||||||
@@ -49,8 +49,11 @@ func (e *TableElement) Render(w io.Writer, ctx RenderContext) error {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
renderText(ctx.table.indentWriter, bs.Current().Style.StylePrimitive, rules.BlockPrefix)
|
ctx.table.styleWriter = NewStyleWriter(ctx, iw, rules.StylePrimitive)
|
||||||
ctx.table.writer = tablewriter.NewWriter(ctx.table.indentWriter)
|
|
||||||
|
renderText(w, bs.Current().Style.StylePrimitive, rules.BlockPrefix)
|
||||||
|
renderText(ctx.table.styleWriter, rules.StylePrimitive, rules.Prefix)
|
||||||
|
ctx.table.writer = tablewriter.NewWriter(ctx.table.styleWriter)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,8 +62,9 @@ func (e *TableElement) Finish(w io.Writer, ctx RenderContext) error {
|
|||||||
ctx.table.writer = nil
|
ctx.table.writer = nil
|
||||||
|
|
||||||
rules := ctx.options.Styles.Table
|
rules := ctx.options.Styles.Table
|
||||||
renderText(ctx.table.indentWriter, ctx.blockStack.Current().Style.StylePrimitive, rules.BlockSuffix)
|
renderText(ctx.table.styleWriter, rules.StylePrimitive, rules.Suffix)
|
||||||
return nil
|
renderText(ctx.table.styleWriter, ctx.blockStack.Current().Style.StylePrimitive, rules.BlockSuffix)
|
||||||
|
return ctx.table.styleWriter.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *TableRowElement) Finish(w io.Writer, ctx RenderContext) error {
|
func (e *TableRowElement) Finish(w io.Writer, ctx RenderContext) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user