func (t *Table) renderMarkdown() string {
	t.Style.setAsciiBoxStyle()
	firstLines := make([]Element, 0, 2)
	if t.headers == nil {
		initial := createRenderStyle(t)
		if initial.columns > 1 {
			row := CreateRow([]interface{}{})
			for i := 0; i < initial.columns; i++ {
				row.AddCell(CreateCell(i+1, &CellStyle{}))
			}
		}
	}
	firstLines = append(firstLines, CreateRow(t.headers))
	firstLines = append(firstLines, firstLines[0])
	t.elements = append(firstLines, t.elements...)
	style := createRenderStyle(t)
	mdRow := CreateRow([]interface{}{})
	for i := 0; i < style.columns; i++ {
		mdRow.AddCell(CreateCell(strings.Repeat("-", style.cellWidths[i]), &CellStyle{}))
	}
	t.elements[1] = mdRow
	b := bytes.NewBuffer(nil)
	if t.title != nil {
		b.WriteString("Table: ")
		b.WriteString(strings.TrimSpace(CreateCell(t.title, &CellStyle{}).Render(style)))
		b.WriteString("\n\n")
	}
	for _, e := range t.elements {
		b.WriteString(e.Render(style))
		b.WriteString("\n")
	}
	return b.String()
}
renderMarkdown returns a string representation of a table in Markdown
markup format using GitHub Flavored Markdown's notation (since tables
are not in the core Markdown spec).
package termtables
import (
	"bytes"
	"os"
	"regexp"
	"runtime"
	"strings"
	"github.com/scylladb/termtables/term"
)
var MaxColumns = 80
type Element interface {
	Render(*renderStyle) string
}
type outputMode int
const (
	outputTerminal outputMode = iota
	outputMarkdown
	outputHTML
)
var outputsEnabled struct {
	UTF8       bool
	HTML       bool
	Markdown   bool
	titleStyle titleStyle
}
var defaultOutputMode outputMode = outputTerminal
type Table struct {
	Style *TableStyle
	elements   []Element
	headers    []interface{}
	title      interface{}
	titleCell  *Cell
	outputMode outputMode
}
func EnableUTF8() {
	outputsEnabled.UTF8 = true
}
func SetModeHTML(onoff bool) {
	outputsEnabled.HTML = onoff
	chooseDefaultOutput()
}
func SetModeMarkdown(onoff bool) {
	outputsEnabled.Markdown = onoff
	chooseDefaultOutput()
}
var utfRe = regexp.MustCompile(`utf\-8|utf8|UTF\-8|UTF8`)
func EnableUTF8PerLocale() {
	locale := getLocale()
	if utfRe.MatchString(locale) {
		EnableUTF8()
	}
}
func getLocale() string {
	if runtime.GOOS == "windows" {
		return "US-ASCII"
	}
	return unixLocale()
}
func unixLocale() string {
	for _, env := range []string{"LC_ALL", "LC_CTYPE", "LANG"} {
		if locale := os.Getenv(env); locale != "" {
			return locale
		}
	}
	return "US-ASCII"
}
func SetHTMLStyleTitle(want titleStyle) {
	outputsEnabled.titleStyle = want
}
func chooseDefaultOutput() {
	if outputsEnabled.HTML {
		defaultOutputMode = outputHTML
	} else if outputsEnabled.Markdown {
		defaultOutputMode = outputMarkdown
	} else {
		defaultOutputMode = outputTerminal
	}
}
func init() {
	sz, err := term.GetSize()
	if err == nil && sz.Columns != 0 {
		MaxColumns = sz.Columns
	}
}
func CreateTable() *Table {
	t := &Table{elements: []Element{}, Style: DefaultStyle}
	if outputsEnabled.UTF8 {
		t.Style.setUtfBoxStyle()
	}
	if outputsEnabled.titleStyle != titleStyle(0) {
		t.Style.htmlRules.title = outputsEnabled.titleStyle
	}
	t.outputMode = defaultOutputMode
	return t
}
func (t *Table) AddSeparator() {
	t.elements = append(t.elements, &Separator{})
}
func (t *Table) AddRow(items ...interface{}) *Row {
	row := CreateRow(items)
	t.elements = append(t.elements, row)
	return row
}
func (t *Table) AddTitle(title interface{}) {
	t.title = title
}
func (t *Table) AddHeaders(headers ...interface{}) {
	t.headers = append(t.headers, headers...)
}
func (t *Table) SetAlign(align TableAlignment, columns ...int) {
	for i := range t.elements {
		row, ok := t.elements[i].(*Row)
		if !ok {
			continue
		}
		for _, column := range columns {
			if column < 0 || column > len(row.cells) {
				continue
			}
			row.cells[column-1].alignment = &align
		}
	}
}
func (t *Table) UTF8Box() {
	t.Style.setUtfBoxStyle()
}
func (t *Table) SetModeHTML() {
	t.outputMode = outputHTML
}
func (t *Table) SetModeMarkdown() {
	t.outputMode = outputMarkdown
}
func (t *Table) SetModeTerminal() {
	t.outputMode = outputTerminal
}
func (t *Table) SetHTMLStyleTitle(want titleStyle) {
	t.Style.htmlRules.title = want
}
func (t *Table) Render() string {
	switch t.outputMode {
	case outputTerminal:
		return t.renderTerminal()
	case outputMarkdown:
		return t.renderMarkdown()
	case outputHTML:
		return t.RenderHTML()
	default:
		panic("unknown output mode set")
	}
}
func (t *Table) renderTerminal() string {
	tt := t.clone()
	if !tt.Style.SkipBorder {
		if tt.title != nil && tt.headers == nil {
			tt.elements = append([]Element{&Separator{where: LINE_SUBTOP}}, tt.elements...)
		} else if tt.title == nil && tt.headers == nil {
			tt.elements = append([]Element{&Separator{where: LINE_TOP}}, tt.elements...)
		} else {
			tt.elements = append([]Element{&Separator{where: LINE_INNER}}, tt.elements...)
		}
	}
	if tt.headers != nil {
		ne := make([]Element, 2)
		ne[1] = CreateRow(tt.headers)
		if tt.title != nil {
			ne[0] = &Separator{where: LINE_SUBTOP}
		} else {
			ne[0] = &Separator{where: LINE_TOP}
		}
		tt.elements = append(ne, tt.elements...)
	}
	if tt.title != nil {
		tt.titleCell = CreateCell(tt.title, &CellStyle{Alignment: AlignCenter, ColSpan: 999})
		ne := []Element{
			&StraightSeparator{where: LINE_TOP},
			CreateRow([]interface{}{tt.titleCell}),
		}
		tt.elements = append(ne, tt.elements...)
	}
	style := createRenderStyle(tt)
	b := bytes.NewBuffer(nil)
	for _, e := range tt.elements {
		b.WriteString(e.Render(style))
		b.WriteString("\n")
	}
	if !style.SkipBorder {
		b.WriteString((&Separator{where: LINE_BOTTOM}).Render(style) + "\n")
	}
	return b.String()
}