gmdtable

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gmdtable

gmdtable converts ordered Go map data into Markdown tables. The module-root package has one public function and preserves the header slice as the table's column order.

Install

Go 1.19 or later is supported.

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

Usage

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 example prints:

| Name     | Language |
| :------- | :------- |
| gmdtable | Go       |

Convert returns an error when headers or data is empty. Values use fmt's default formatting, missing keys render as <nil>, and structural pipes, backslashes, and line breaks are escaped so the content remains in its cell. Each column is padded to its widest cell, and its left-aligned separator uses the same width with at least three hyphens.

Run the complete example with go run ./examples/basic.

Website and documentation

The examples page renders examples/basic/main.go and example_test.go directly from checked-in Go source. The API page extracts exported declarations and GoDoc from the module-root package.

Development

Run the package checks from the repository root:

gofmt -w .
go mod tidy
go test ./...
go test -race ./...
go vet ./...
go build ./...
go run ./examples/basic

Generate and validate the final GitHub Pages artifact:

go run ./cmd/sitegen build
go run ./cmd/sitegen validate

Preview the production-like artifact at http://127.0.0.1:4173/gmdtable/:

go run ./cmd/sitegen preview

dist/pages is generated and ignored by Git. Update site.config.json, Go source, templates, or site assets, then rebuild instead of editing generated Pages files.

License

The Go package and project-authored website code are available under the MIT License. Vendored Bootstrap notices are in guides/THIRD_PARTY_NOTICES.md.

Documentation

Overview

Package gmdtable converts ordered column headers and map-backed row data into Markdown tables.

Convert uses the header slice as both the table schema and the column order. Cell values are formatted with fmt's default representation, then structural Markdown table characters are escaped. The package performs no I/O and has no runtime dependencies outside the Go standard library.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(headers []string, data []map[string]interface{}) (string, error)

Convert returns a Markdown table containing headers and data.

The order of headers determines the column order. Each row is read by header key, and values use fmt's default formatting. Pipes, backslashes, and line breaks are escaped so they remain within their cells. Columns are padded to their widest cell. Convert returns an error when headers or data is empty.

Example
package main

import (
	"fmt"

	"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 {
		panic(err)
	}
	fmt.Println(table)
}
Output:
| Name     | Language |
| :------- | :------- |
| gmdtable | Go       |

Types

This section is empty.

Directories

Path Synopsis
cmd
sitegen command
Command sitegen builds, validates, and previews the generated GitHub Pages website.
Command sitegen builds, validates, and previews the generated GitHub Pages website.
examples
basic command
Command basic demonstrates the public Markdown-table conversion API.
Command basic demonstrates the public Markdown-table conversion API.
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL