markdown

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Markdown core does not support tables; for the most portable support, assuming HTML is the final target, use the `html` sub-package instead.

Support for GitHub-Flavored Markdown's Tables is fairly widespread in markdown packages. That's the dialect which we speak at this time.

Note that the data model supported by GFM tables is very limited and is likely to break on a number of valid inputs. We attempt to deal "safely" with this, to meet the security model, but it's likely that there are inputs which break the integrity of the markdown table for various renderers. Again, the solution is to use the HTMLTable wrapper instead.

So why have this sub-package? In my experience, people working on documentation like to be able to use the same input data and ask the tools to generate markdown, which can then be included as-is, for output in various formats. Thus we have _two_ target audiences: a human reviewing our output as it goes into .md documents, and people viewing the rendered tables later. We need to look "decent" for both, but can defer sanitization to the human review step.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotCellProperties = errors.New("markdowntable: width-set: not given a cell")

Functions

func CellPropertyExtractWidth

func CellPropertyExtractWidth(cell *tabular.Cell) int

func Render

func Render(t tabular.Table) (string, error)

Render takes a tabular.Table and creates a default options MarkdownTable object and then calls the Render method upon it.

func RenderTo

func RenderTo(t tabular.Table, w io.Writer) error

RenderTo takes a tabular.Table and creates a default options MarkdownTable object and calls the RenderTo method upon it.

Types

type MarkdownTable

type MarkdownTable struct {
	tabular.Table
}

A MarkdownTable wraps a tabular.Table to act as a render control for Markdown output.

func New

func New() *MarkdownTable

New returns a MarkdownTable with a new Table inside it, access via .Table or just use the interface methods on the MarkdownTable.

func Wrap

func Wrap(t tabular.Table) *MarkdownTable

Wrap returns a MarkdownTable rendering object for the given tabular.Table.

func (*MarkdownTable) Render

func (mt *MarkdownTable) Render() (string, error)

Render takes a tabular Table and returns a string representing the fully rendered table or an error.

func (*MarkdownTable) RenderTo

func (mt *MarkdownTable) RenderTo(w io.Writer) error

RenderTo writes the table to the provided writer, stopping if it encounters an error.

Jump to

Keyboard shortcuts

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