csv2md: github.com/mohae/csv2md Index | Files

package csv2md

import "github.com/mohae/csv2md"

Package csv2md transforms CSV-encoded data into Github Flavored Mardown, GFM, tables. The field names, field alignment, and field text effects can be specified: either by providing a format file or by configuring the Transmogrifier. If the field names have not been set, the first record of the CSV-encoded data should have a header record.

It is assumed that all CSV-encoded data contains a header record, even if the field names have been set, unless the HasHeaderRecord is set to false. If the field names has been set and the CSV-encoded data has a header record, the first record in the data will be ignored.

Index

Package Files

csv2md.go

Variables

var ErrNoFormatData = errors.New("no format data")

ErrNoFormatData occurs when no data is found in the provided reader.

type ShortWriteError Uses

type ShortWriteError struct {
    // contains filtered or unexported fields
}

ShortWriteError occurs when the number of bytes written is less than the number of bytes to be written.

func (ShortWriteError) Error Uses

func (e ShortWriteError) Error() string

type Transmogrifier Uses

type Transmogrifier struct {
    // HasHeaderRecord specifies whether or not the CSV-encoded data's
    // first record has field names.  If false, either the field names
    // must be set; either by calling SetFieldNames or SetFmt.  In either
    // case, the number of fields must match the number of fields per
    // record in the CSV data.
    HasHeaderRecord bool
    // CSV is a csv.Reader.  This is exported so that the caller can
    // can configure the CSV reader.
    CSV *csv.Reader
    // contains filtered or unexported fields
}

Transmogrifier turns CSV data into a markdown table

func NewTransmogrifier Uses

func NewTransmogrifier(r io.Reader, w io.Writer) *Transmogrifier

NewTransmogrifier returns an initialized Transmogrifier for transmogrifierication of CSV-encoded data to GitHub Flavored Markdown tables.

func (*Transmogrifier) BytesWritten Uses

func (t *Transmogrifier) BytesWritten() int64

BytesWritten returns the number of bytes written to the writer.

func (*Transmogrifier) MDTable Uses

func (t *Transmogrifier) MDTable() error

MDTable reads from the configured reader, CSV, transforms the data into a GitHub Flavored Markdown table, applying justification and text styling, and writes the resulting bytes to the Transmogrifier's writer.

func (*Transmogrifier) NewLine Uses

func (t *Transmogrifier) NewLine() string

NewLine returns the current new line sequence.

func (*Transmogrifier) SetFieldAlignment Uses

func (t *Transmogrifier) SetFieldAlignment(vals []string)

SetFieldAlignment sets the alignment, justification, used for each field in the table.

Valid alignment values:

* Left justification
  * l
  * left
  * :--
* Centered text
  * c
  * centered
  * center
  * :--:
* Right justification
  * r
  * right
  * --:
* No justification
  * empty string

func (*Transmogrifier) SetFieldNames Uses

func (t *Transmogrifier) SetFieldNames(vals []string)

SetFieldNames sets the names for each field; these values are used in the table header as each column's, field's, name.

func (*Transmogrifier) SetFieldStyle Uses

func (t *Transmogrifier) SetFieldStyle(vals []string)

SetFieldStyle sets the text styling for a record's field. Accepted values:

* Bold
  * b
  * bold
  * __
* Italics
  * i
  * italics
  * italic
  * _
* Strikethrough
  * s
  * strikethrough
  * ~~
* No text styling
  * empty string

func (*Transmogrifier) SetFmt Uses

func (t *Transmogrifier) SetFmt(r io.Reader) error

SetFmt takes a reader and reads the format information from it as CSV encoded data. The CSV reader used to read the format information is configured to be consistent with CSV's configuration under the assumption that the CSV data in the format file will be encoded the same way as the actual CSV data; e.g. if the CSV data is tab delimited, the format file will also be tab delimited.

func (*Transmogrifier) SetNewLine Uses

func (t *Transmogrifier) SetNewLine(s string)

SetNewLine sets the newLine value based on the received value. If the received value is not recognized, nothing is done.

Valid new line values:

* Carriage Return (new line)
  * cr
  * CR
  * \n
* Line Feed
  * lf
  * LF
  * \r
* Carriage Return/Line Feed
  * crlf
  * CRLF
  * \r\n

For a new line to occur, Markdown requires the line to terminate with either two spaces, " ", or have a double line feed. The newLine is prefixed with two spaces.

Package csv2md imports 5 packages (graph) and is imported by 1 packages. Updated 2016-08-01. Refresh now. Tools for package owners.