mdt

package module
v0.0.0-...-3ae3b51 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2015 License: MIT Imports: 7 Imported by: 0

README

mdt Build Status

A markdown table generation tool from CSV/TSV.

Usage

$ mdt < hoge.csv
| headerA | headerB                |
| ------- | ---------------------- |
| short   | very very long content |

mdt is very simple command line tool, so you can integrate with other tools like pbpaste, Automator, etc...

For example, you can use mdt with Automator Service on GitHub PR/Issue page.

mdt

Features

  • Convert from CSV/TSV.
  • Auto formatting.
  • Support multibyte contents.
  • Define align at CSV/TSV header ex. :headerA:, headerB:
  • Repeating execution.
  • Specify a header line (-H option).

See also examples.

Installation

$ go get github.com/monochromegane/mdt/...

Integration

Automator

mdt_with_automator

  1. Create new Automator Service.
  2. Select Run Shell Script action.
  3. Service receives selected -> text
  4. Check Output replaces selected text
  5. Input /path/to/mdt at Run Shell Script (pass input is to stdin).

You can call the service by shortcut key.

System Preferences > Keyboard > Shortcuts tab > Services > Select your service, and set shortcut.

Contribution

  1. Fork it
  2. Create a feature branch
  3. Commit your changes
  4. Rebase your local changes against the master branch
  5. Run test suite with the go test ./... command and confirm that it passes
  6. Run gofmt -s
  7. Create new Pull Request

License

MIT

Author

monochromegane

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(header string, r io.Reader) (string, error)
Example (Align)
package main

import (
	"fmt"
	"strings"

	"github.com/monochromegane/mdt"
)

func main() {
	r := strings.NewReader(`
headerA:, :headerB:
content, content
`)
	result, _ := mdt.Convert("", r)
	fmt.Printf("%s", result)

}
Output:

| headerA | headerB |
| -------:|:-------:|
| content | content |
Example (Csv)
package main

import (
	"fmt"
	"strings"

	"github.com/monochromegane/mdt"
)

func main() {
	r := strings.NewReader(`
headerA, headerB
content, content
`)
	result, _ := mdt.Convert("", r)
	fmt.Printf("%s", result)

}
Output:

| headerA | headerB |
| ------- | ------- |
| content | content |
Example (Format)
package main

import (
	"fmt"
	"strings"

	"github.com/monochromegane/mdt"
)

func main() {
	r := strings.NewReader(`
headerA, headerB
short, very very long content
`)
	result, _ := mdt.Convert("", r)
	fmt.Printf("%s", result)

}
Output:

| headerA | headerB                |
| ------- | ---------------------- |
| short   | very very long content |
Example (Multibyte)
package main

import (
	"fmt"
	"strings"

	"github.com/monochromegane/mdt"
)

func main() {
	r := strings.NewReader(`
headerA, headerB
マルチバイト文字, content
マルチバイト文字, content
`)
	result, _ := mdt.Convert("", r)
	fmt.Printf("%s", result)

}
Output:

| headerA          | headerB |
| ---------------- | ------- |
| マルチバイト文字 | content |
| マルチバイト文字      | content |
Example (Repeat)
package main

import (
	"fmt"
	"strings"

	"github.com/monochromegane/mdt"
)

func main() {
	r := strings.NewReader(`
| headerA | headerB |
| -------:|:-------:|
| content | content |
next content, next content
`)
	result, _ := mdt.Convert("", r)
	fmt.Printf("%s", result)

}
Output:

| headerA      | headerB      |
| ------------:|:------------:|
| content      | content      |
| next content | next content |
Example (Short)
package main

import (
	"fmt"
	"strings"

	"github.com/monochromegane/mdt"
)

func main() {
	r := strings.NewReader(`
#,A
1,B
`)
	result, _ := mdt.Convert("", r)
	fmt.Printf("%s", result)

}
Output:

| #   | A   |
| --- | --- |
| 1   | B   |
Example (Short_align)
package main

import (
	"fmt"
	"strings"

	"github.com/monochromegane/mdt"
)

func main() {
	r := strings.NewReader(`
#:,:A:
1,B
`)
	result, _ := mdt.Convert("", r)
	fmt.Printf("%s", result)

}
Output:

| #   | A   |
| ---:|:---:|
| 1   | B   |
Example (Tsv)
package main

import (
	"fmt"
	"strings"

	"github.com/monochromegane/mdt"
)

func main() {
	r := strings.NewReader(`
headerA	headerB
content	content
`)
	result, _ := mdt.Convert("", r)
	fmt.Printf("%s", result)

}
Output:

| headerA | headerB |
| ------- | ------- |
| content | content |
Example (With_header)
package main

import (
	"fmt"
	"strings"

	"github.com/monochromegane/mdt"
)

func main() {
	r := strings.NewReader(`
content, content
`)
	result, _ := mdt.Convert("headerA,headerB", r)
	fmt.Printf("%s", result)

}
Output:

| headerA | headerB |
| ------- | ------- |
| content | content |
Example (With_header_align)
package main

import (
	"fmt"
	"strings"

	"github.com/monochromegane/mdt"
)

func main() {
	r := strings.NewReader(`
content, content
`)
	result, _ := mdt.Convert("headerA:,:headerB", r)
	fmt.Printf("%s", result)

}
Output:

| headerA | headerB |
| -------:|:------- |
| content | content |

Types

This section is empty.

Directories

Path Synopsis
cmd
mdt

Jump to

Keyboard shortcuts

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