Skip to content

shiv-source/markdownTable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

markdownTable

A Go package to generate Markdown tables from header and body data. This package automatically adjusts column widths based on the longest entry in each column, ensuring that the table is aligned and visually clear when rendered in Markdown.

Features

  • Converts a given header and body data into a well-formatted Markdown table.
  • Automatically adjusts column widths based on the longest entry (including headers).
  • Truncates rows with fewer columns than the header to maintain consistency.
  • Provides a clean and simple way to create Markdown tables programmatically in Go.

Installation

To install the markdownTable package, use the following Go command:

go get github.com/shiv-source/markdownTable

Example Usage

Here’s an example of how to use the CreateMarkdownTable function:

package main

import (
	"fmt"
	"github.com/shiv-source/markdownTable"
)

func main() {
	head := []string{"ID", "Name", "Age"}
	body := [][]string{
		{"1", "John", "26"},
		{"2", "Bob", "25"},
		{"3", "Alice", "27"},
	}

	// Create the Markdown table
	markdownTable := markdownTable.CreateMarkdownTable(head, body)

	// Print the Markdown table
	fmt.Println(markdownTable)
}

Expected Output:

| ID  | Name         | Age |
|-----|--------------|-----|
| 1   | John         | 26  |
| 2   | Bob          | 25  |
| 3   | Alice        | 27  |

Function Signature

func CreateMarkdownTable(head []string, body [][]string) string

Parameters:

  • head: A slice of strings representing the column headers of the table.
  • body: A slice of slices, where each inner slice represents a row of data in the table.

Returns:

  • A string containing the Markdown-formatted table.

Contributing

If you would like to contribute to this project, feel free to fork the repository, make changes, and create a pull request. All contributions are welcome!

Steps to contribute:

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature-name).
  3. Commit your changes (git commit -am 'Add new feature').
  4. Push to the branch (git push origin feature-name).
  5. Create a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A Go package to generate Markdown table

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages