mdformatter

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2020 License: Apache-2.0 Imports: 20 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 SourceContext, infoString []byte, code []byte) ([]byte, error)
	Close(ctx SourceContext) error
}

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 FormatFrontMatter added in v0.2.0

type FormatFrontMatter struct{}

func (FormatFrontMatter) Close added in v0.2.0

func (FormatFrontMatter) TransformFrontMatter added in v0.2.0

func (FormatFrontMatter) TransformFrontMatter(_ SourceContext, frontMatter map[string]interface{}) ([]byte, error)

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 SourceContext, frontMatter map[string]interface{}) ([]byte, error)
	Close(ctx SourceContext) error
}

type LinkTransformer

type LinkTransformer interface {
	TransformDestination(ctx SourceContext, destination []byte) ([]byte, error)
	Close(ctx SourceContext) error
}

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(_ SourceContext, _ map[string]interface{}) ([]byte, error)

type SourceContext added in v0.2.0

type SourceContext struct {
	context.Context

	Filepath string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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