mdformatter

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(ctx context.Context, logger log.Logger, files []string, opts ...Option) error

Format formats given markdown files in-place. IsFormatted `With...` function to see what modifiers you can add.

Types

type CodeBlockTransformer

type CodeBlockTransformer interface {
	TransformCodeBlock(ctx context.Context, docPath string, infoString []byte, code []byte) ([]byte, error)
	io.Closer
}

type Diffs

type Diffs []gitdiff.Diff

func IsFormatted

func IsFormatted(ctx context.Context, logger log.Logger, files []string, opts ...Option) (diffs Diffs, err error)

IsFormatted tries to formats given markdown files and return Diff if files are not formatted. If diff is empty it means all files are formatted.

func (Diffs) String

func (d Diffs) String() string

type Formatter

type Formatter struct {
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, opts ...Option) *Formatter

func (*Formatter) Format

func (f *Formatter) Format(file *os.File, out io.Writer) error

Format writes formatted input file into out writer.

type FrontMatterTransformer

type FrontMatterTransformer interface {
	TransformFrontMatter(ctx context.Context, docPath string, frontMatter map[string]interface{}) ([]byte, error)
	io.Closer
}

type LinkTransformer

type LinkTransformer interface {
	TransformDestination(ctx context.Context, docPath string, destination []byte) ([]byte, error)
	io.Closer
}

type Option

type Option func(*Formatter)

Option is a functional option type for Formatter objects.

func WithCodeBlockTransformer

func WithCodeBlockTransformer(cb CodeBlockTransformer) Option

WithMetaBlockTransformer allows you to override the default CodeBlockTransformer.

func WithFrontMatterTransformer

func WithFrontMatterTransformer(fm FrontMatterTransformer) Option

WithFrontMatterTransformer allows you to override the default FrontMatterTransformer.

func WithLinkTransformer

func WithLinkTransformer(l LinkTransformer) Option

WithLinkTransformer allows you to override the default LinkTransformer.

type RemoveFrontMatter

type RemoveFrontMatter struct{}

func (RemoveFrontMatter) Close

func (RemoveFrontMatter) Close() error

func (RemoveFrontMatter) TransformFrontMatter

func (RemoveFrontMatter) TransformFrontMatter(_ context.Context, _ string, frontMatter map[string]interface{}) ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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