Documentation
¶
Overview ¶
Package mdfmt contains basic markdown reformatting functionality.
Use this package to write CLI help text as markdown and get nicely-rendered terminal output.
The sample CLI in cmd/sample uses this package to format cmd/sample/docs/testfile.md.
Run go run ./cmd/sample testfile to view the rendered document.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StaticColumns ¶
StaticColumns is a static columns setting.
func WriteTable ¶
WriteTable writes a markdown table with equal spaced columns. Text within the columns will be left-aligned.
func WriteTableWithAlignment ¶
func WriteTableWithAlignment(header []string, rows [][]string, alignment []TextAlignment) string
WriteTableWithAlignment writes a markdown table with equal spaced columns. Text within the columns will be aligned according to the alignments given.
Types ¶
type Formatter ¶
type Formatter struct { Header func(text string, loc Location) string // reformats headers Link func(text, url string, loc Location) string // reformats links Code func(code string, loc Location) string // reformats inline code blocks CodeBlock func(code string, loc Location) string // reformats multiline code blocks Bold func(text string, loc Location) string // reformats bolded text Italics func(text string, loc Location) string // reformats italicized text Indent func(loc Location) string // produces indent for a line's location // produce column width for wrapping // (nil function or 0 return value disables wrapping) Columns func() int // CodeBlockWrapMode signifies a code block wrapping style. CodeBlockWrapMode WrapMode }
Formatter formats Markdown for terminal output.
type Location ¶
type Location struct { Level int // Header level of the current section Header bool // Line is a header line CodeBlock bool // Line is within a multiline code block CodeBlockLang string // Language identifier for the code block CodeBlockLevel int // Number of "`" characters used to start the multiline code block Table bool // In a table Comment bool // Line is in an HTML comment }
Location describes the current location of text in a markdown document.
type TextAlignment ¶
type TextAlignment uint8
TextAlignment defines text alignment.
const ( TextAlignmentDefault TextAlignment = iota TextAlignmentLeft TextAlignmentCenter TextAlignmentRight )
Defined text alignments.