codefmt

package
v0.0.0-...-59817e7 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package codefmt contains basic code reformatting functionality.

Use this package to write CLI examples as commented bash scripts and get nicely-rendered terminal output.

Index

Constants

This section is empty.

Variables

View Source
var (
	Bash = LangInfo{
		LineCommentStart: "#",
	}

	Go = LangInfo{
		LineCommentStart: "//",
	}
)

Defined LangInfo for reuse.

Functions

func StaticColumns

func StaticColumns(cols int) func() int

StaticColumns is a static columns setting.

Types

type Formatter

type Formatter struct {
	Comment func(comment string, loc Location) string // reformats inline code blocks
	Code    func(code string, loc Location) string    // reformats inline code blocks
	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

	WrapMode WrapMode
}

Formatter formats Markdown for terminal output.

func (*Formatter) Format

func (format *Formatter) Format(codeText string, lang LangInfo) string

Format formats markdown text according the Formatter's rules.

type LangInfo

type LangInfo struct {
	LineCommentStart string // Starts line comments

}

LangInfo defines basic language information needed for parsing.

type Location

type Location struct {
	LineComment bool // In a line comment

}

Location describes the current location of text in a document.

type WrapMode

type WrapMode uint8

WrapMode signifies a code block wrapping style.

const (
	Default                   WrapMode = iota
	WrapToCurrentIndentation           // Indent wrapped lines to the current line's indentation
	WrapToStartingIndentation          // Indent wrapped lines to the starting indentation of the sectin
)

Defined code block wrapping styles.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳