termd

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2020 License: MIT Imports: 9 Imported by: 0

README

Termd

Package termd provides terminal markdown rendering, with code block syntax highlighting support.

Features

  • Code block syntax highlighting (JSON-friendly for loading from user config)
  • Word wrapping to the specified column width
  • Terminal specific styling (still looks like markdown but it's cleaned up for the term)


GoDoc

Sponsors

This project is sponsored by CTO.ai, making it easy for development teams to create and share workflow automations without leaving the command line.

Documentation

Overview

Package termd provides terminal markdown rendering, with code block syntax highlighting support.

Example
var c termd.Compiler

c.SyntaxHighlighter = termd.SyntaxTheme{
	"keyword": termd.Style{},
	"comment": termd.Style{
		Color: "#323232",
	},
	"literal": termd.Style{
		Color: "#555555",
	},
	"name": termd.Style{
		Color: "#777777",
	},
	"name.function": termd.Style{
		Color: "#444444",
	},
	"literal.string": termd.Style{
		Color: "#333333",
	},
}

b, _ := ioutil.ReadFile("testdata/example.md")
fmt.Printf("%s\n", c.Compile(string(b)))
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Compiler

type Compiler struct {
	// Columns is the number of columns to wrap text, defaulting to 90.
	Columns int

	// Markdown is an optional instance of a blackfriday markdown parser,
	// defaulting to one with CommonExtensions enabled.
	Markdown *blackfriday.Markdown

	// SyntaxHighlighter is an optional syntax highlighter for code blocks,
	// using the low-level SyntaxHighlighter interface, or SyntaxTheme map.
	SyntaxHighlighter
	// contains filtered or unexported fields
}

Compiler is the markdown to text compiler. The zero value can be used.

func (*Compiler) Compile

func (c *Compiler) Compile(s string) string

Compile returns a terminal-styled plain text representation of a markdown string.

type Style

type Style struct {
	Color      string `json:"color"`
	Background string `json:"background"`
	Bold       bool   `json:"bold"`
	Faint      bool   `json:"faint"`
	Italic     bool   `json:"italic"`
	Underline  bool   `json:"underline"`
}

Style is the configuration used to style a particular token.

type SyntaxHighlighter

type SyntaxHighlighter interface {
	Token(chroma.Token) string
}

SyntaxHighlighter is the interface used to highlight blocks of code.

type SyntaxTheme

type SyntaxTheme map[string]Style

SyntaxTheme is a map of token names to style configurations.

func (SyntaxTheme) Token

func (c SyntaxTheme) Token(t chroma.Token) string

Token implementation.

Jump to

Keyboard shortcuts

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