markdown

package module
v0.0.0-...-fa119f0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: MIT Imports: 24 Imported by: 0

README

go-term-markdown

Build Status GoDoc Go Report Card codecov GitHub license Gitter chat

go-term-markdown is a go package implementing a Markdown renderer for the terminal.

Note: Markdown being originally designed to render as HTML, rendering in a terminal is occasionally challenging and some adaptation had to be made.

Features:

  • formatting
  • lists
  • tables
  • images
  • code blocks with syntax highlighting
  • basic HTML support

Note: this renderer is packaged as a standalone terminal viewer at https://github.com/MichaelMure/mdr/

Usage

import (
	"fmt"
	"io/ioutil"

	markdown "github.com/MichaelMure/go-term-markdown"
)

func main() {
	path := "Readme.md"
	source, err := ioutil.ReadFile(path)
	if err != nil {
		panic(err)
	}

	result := markdown.Render(string(source), 80, 6)

	fmt.Println(result)
}

Example

Here is the Readme of go-term-text rendered with go-term-markdown:

rendering example

Here is an example of table rendering:

table rendering

Origin

This package has been extracted from the git-bug project. As such, its aim is to support this project and not to provide an all-in-one solution. Contributions or full-on takeover as welcome though.

Contribute

PRs accepted.

License

MIT

Documentation

Index

Constants

View Source
const (
	NoDithering = DitheringMode(iota)
	DitheringWithBlocks
	DitheringWithChars
)

Variables

View Source
var (
	Green        = color.New(color.FgGreen).SprintFunc()
	HiGreen      = color.New(color.FgHiGreen).SprintFunc()
	GreenBold    = color.New(color.FgGreen, color.Bold).SprintFunc()
	Blue         = color.New(color.FgBlue).SprintFunc()
	BlueBgItalic = color.New(color.BgBlue, color.Italic).SprintFunc()
	Red          = color.New(color.FgRed).SprintFunc()
)

Functions

func Extensions

func Extensions() parser.Extensions

Extensions returns the bitmask of extensions supported by this renderer. The output of this function can be used to instantiate a new markdown parser using the `NewWithExtensions` function.

func NewRenderer

func NewRenderer(lineWidth int, leftPad int, opts ...Options) *renderer

NewRenderer creates a new instance of the console renderer

func Render

func Render(source string, lineWidth int, leftPad int, opts ...Options) []byte

Types

type CellAlign

type CellAlign int
const (
	CellAlignLeft CellAlign = iota
	CellAlignRight
	CellAlignCenter
	CellAlignCopyHeader
)

type DitheringMode

type DitheringMode uint8

DitheringMode type is used for image scale dithering mode constants.

type Options

type Options func(r *renderer)

func WithBlockquoteShades

func WithBlockquoteShades(shades []shadeFmt) Options

Use a custom collection of ANSI colors for the blockquotes

func WithContinuity

func WithContinuity(prev renderer) Options

WithContinuity makes the renderer resume heading numbers where prev left off.

func WithHeadingShades

func WithHeadingShades(shades []shadeFmt) Options

Use a custom collection of ANSI colors for the headings

func WithImageDithering

func WithImageDithering(mode DitheringMode) Options

Dithering mode for ansimage Default is fine directly through a terminal DitheringWithBlocks is recommended if a terminal UI library is used

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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