Add columns
Append header names in the required order and add matching keys to each row map.
Compiled, executable documentation
These listings come directly from checked-in Go source. Run them locally to exercise github.com/tzfqh/gmdtable; the website does not reimplement the package in the browser or send code to a remote execution service.
The generator reads this listing from examples/basic/main.go. It supplies ordered headers and one row to the public Convert function.
go run ./examples/basicExpected output
| Name | Language |
| :------- | :------- |
| gmdtable | Go |// Command basic demonstrates the public Markdown-table conversion API.
package main
import (
"fmt"
"log"
"github.com/tzfqh/gmdtable"
)
func main() {
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)
}
The source-derived ExampleConvert function is compiled, and its output comment is checked by go test ./.... This keeps the example synchronized with the public API and exact Markdown output.
go test ./...package gmdtable_test
import (
"fmt"
"github.com/tzfqh/gmdtable"
)
func ExampleConvert() {
headers := []string{"Name", "Language"}
data := []map[string]interface{}{{"Name": "gmdtable", "Language": "Go"}}
table, err := gmdtable.Convert(headers, data)
if err != nil {
panic(err)
}
fmt.Println(table)
// Output:
// | Name | Language |
// | :------- | :------- |
// | gmdtable | Go |
}
Append header names in the required order and add matching keys to each row map.
Check the returned error when the headers or data may be empty, before using the generated table.
The generated API documentation reflects the current exported declaration and GoDoc comment.