mdformatter

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: Apache-2.0 Imports: 27 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.

func FormatFrontMatter added in v0.2.0

func FormatFrontMatter(m map[string]interface{}) ([]byte, error)

Types

type BackMatterTransformer added in v0.9.0

type BackMatterTransformer interface {
	TransformBackMatter(ctx SourceContext) ([]byte, error)
	Close(ctx SourceContext) error
}

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 FormatFrontMatterTransformer added in v0.9.0

type FormatFrontMatterTransformer struct{}

func (FormatFrontMatterTransformer) Close added in v0.9.0

func (FormatFrontMatterTransformer) TransformFrontMatter added in v0.9.0

func (FormatFrontMatterTransformer) 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 WithBackMatterTransformer added in v0.9.0

func WithBackMatterTransformer(bm BackMatterTransformer) Option

WithBackMatterTransformer allows you to override the default BackMatterTransformer.

func WithCodeBlockTransformer

func WithCodeBlockTransformer(cb CodeBlockTransformer) Option

WithCodeBlockTransformer 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.

func WithMetrics added in v0.9.0

func WithMetrics(reg *prometheus.Registry) Option

WithMetrics allows you to pass in Prometheus registry.

func WithSoftWraps added in v0.9.0

func WithSoftWraps() Option

WithCodeBlockTransformer allows you to override default softWrap.

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
	LineNumbers string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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