mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-06 08:57:14 -04:00
fix: properly set table alignments
This commit is contained in:
committed by
Christian Muehlhaeuser
parent
ba919abf98
commit
9e3abf6f65
+2
-1
@@ -295,7 +295,8 @@ func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element {
|
|||||||
|
|
||||||
// Tables
|
// Tables
|
||||||
case astext.KindTable:
|
case astext.KindTable:
|
||||||
te := &TableElement{}
|
table := node.(*astext.Table)
|
||||||
|
te := &TableElement{table: table}
|
||||||
return Element{
|
return Element{
|
||||||
Entering: "\n",
|
Entering: "\n",
|
||||||
Renderer: te,
|
Renderer: te,
|
||||||
|
|||||||
+18
-1
@@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/muesli/reflow/indent"
|
"github.com/muesli/reflow/indent"
|
||||||
"github.com/olekukonko/tablewriter"
|
"github.com/olekukonko/tablewriter"
|
||||||
|
astext "github.com/yuin/goldmark/extension/ast"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A TableElement is used to render tables.
|
// A TableElement is used to render tables.
|
||||||
@@ -13,6 +14,7 @@ type TableElement struct {
|
|||||||
styleWriter *StyleWriter
|
styleWriter *StyleWriter
|
||||||
header []string
|
header []string
|
||||||
cell []string
|
cell []string
|
||||||
|
table *astext.Table
|
||||||
}
|
}
|
||||||
|
|
||||||
// A TableRowElement is used to render a single row in a table.
|
// A TableRowElement is used to render a single row in a table.
|
||||||
@@ -51,7 +53,22 @@ func (e *TableElement) Render(w io.Writer, ctx RenderContext) error {
|
|||||||
|
|
||||||
renderText(w, ctx.options.ColorProfile, bs.Current().Style.StylePrimitive, rules.BlockPrefix)
|
renderText(w, ctx.options.ColorProfile, bs.Current().Style.StylePrimitive, rules.BlockPrefix)
|
||||||
renderText(ctx.table.styleWriter, ctx.options.ColorProfile, style, rules.Prefix)
|
renderText(ctx.table.styleWriter, ctx.options.ColorProfile, style, rules.Prefix)
|
||||||
ctx.table.writer = tablewriter.NewWriter(ctx.table.styleWriter)
|
table := tablewriter.NewWriter(ctx.table.styleWriter)
|
||||||
|
|
||||||
|
alignments := make([]int, len(e.table.Alignments))
|
||||||
|
for i, a := range e.table.Alignments {
|
||||||
|
switch a {
|
||||||
|
case astext.AlignLeft:
|
||||||
|
alignments[i] = tablewriter.ALIGN_LEFT
|
||||||
|
case astext.AlignCenter:
|
||||||
|
alignments[i] = tablewriter.ALIGN_CENTER
|
||||||
|
case astext.AlignRight:
|
||||||
|
alignments[i] = tablewriter.ALIGN_RIGHT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
table.SetColumnAlignment(alignments)
|
||||||
|
|
||||||
|
ctx.table.writer = table
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user