From 29ea5f002ac64c4aefcd4568ac6c6d6c05f46f63 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 16 Dec 2019 21:58:40 +0100 Subject: [PATCH] Styles can override the table's separators --- ansi/style.go | 9 ++++++++- ansi/table.go | 14 +++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ansi/style.go b/ansi/style.go index 1335ad5..0c13205 100644 --- a/ansi/style.go +++ b/ansi/style.go @@ -78,6 +78,13 @@ type StyleList struct { LevelIndent uint `json:"level_indent"` } +type StyleTable struct { + StyleBlock + CenterSeparator *string `json:"center_separator"` + ColumnSeparator *string `json:"column_separator"` + RowSeparator *string `json:"row_separator"` +} + type StyleConfig struct { Document StyleBlock `json:"document"` BlockQuote StyleBlock `json:"block_quote"` @@ -111,7 +118,7 @@ type StyleConfig struct { Code StyleBlock `json:"code"` CodeBlock StyleCodeBlock `json:"code_block"` - Table StyleBlock `json:"table"` + Table StyleTable `json:"table"` DefinitionList StyleBlock `json:"definition_list"` DefinitionTerm StylePrimitive `json:"definition_term"` diff --git a/ansi/table.go b/ansi/table.go index 5d6e2e6..e77ec5c 100644 --- a/ansi/table.go +++ b/ansi/table.go @@ -58,10 +58,22 @@ func (e *TableElement) Render(w io.Writer, ctx RenderContext) error { } func (e *TableElement) Finish(w io.Writer, ctx RenderContext) error { + rules := ctx.options.Styles.Table + + ctx.table.writer.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false}) + if rules.CenterSeparator != nil { + ctx.table.writer.SetCenterSeparator(*rules.CenterSeparator) + } + if rules.ColumnSeparator != nil { + ctx.table.writer.SetColumnSeparator(*rules.ColumnSeparator) + } + if rules.RowSeparator != nil { + ctx.table.writer.SetRowSeparator(*rules.RowSeparator) + } + ctx.table.writer.Render() ctx.table.writer = nil - rules := ctx.options.Styles.Table renderText(ctx.table.styleWriter, rules.StylePrimitive, rules.Suffix) renderText(ctx.table.styleWriter, ctx.blockStack.Current().Style.StylePrimitive, rules.BlockSuffix) return ctx.table.styleWriter.Close()