Go Markdown table generator

gmdtable

gmdtable converts ordered Go map data into Markdown tables with a small standard-library API.

Install
go get github.com/tzfqh/gmdtable

Install the package

Use Go 1.19 or later. The public package lives at the module root and uses only the Go standard library at runtime.

go get github.com/tzfqh/gmdtable
import gmdtable "github.com/tzfqh/gmdtable"

Generate a Markdown table

Pass headers in the required column order, then provide one map for each row. Convert reads every map using the header keys and formats values with Go's default representation.

Open the complete basic example
headers := []string{"Name", "Language"}
data := []map[string]interface{}{
    {"Name": "gmdtable", "Language": "Go"},
}

table, err := gmdtable.Convert(headers, data)
if err != nil {
    log.Fatal(err)
}
fmt.Println(table)

Verified package behavior

The implementation and executable tests define these behaviors.

Ordered columns

The header slice controls both the table schema and column order, independent of map iteration order.

Table-safe cells

Rows accept map[string]interface{} values, use fmt's default formatting, and escape structural cell content.

Explicit input errors

Convert returns an error when the headers or data slice is empty.

Package resources

Use source-derived documentation to verify the package contract before changing output formatting.

Requires Go 1.19 or later and is available under the MIT License.