markdownTable

package module
v0.0.0-...-33ea2ec Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2025 License: MIT Imports: 1 Imported by: 0

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMarkdownTable

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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