goldmarkmodifier

package module
v0.0.0-...-396af42 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: MIT Imports: 6 Imported by: 0

README

goldmarkmodifier

goldmarkmodifier is a subproject of kbs (WIP), which is responsible for providing the "Markdown AST editing capabilities" needed to implement the "markdown project" in kbs.

The goldmarkmodifier is a tool that allows you to modify the ast of markdown, extending the functionality of goldmark to allow you to edit the ast of markdown generated by goldmark.

With goldmarkmodifier you can easily edit the markdown asts parsed by goldmark as follows:

  • Insert arbitrary text
  • Parse and insert another Markdown file

In addition, goldmarkmodifier also provides some quick ways to manipulate ast by providing a data structure called Mapping, which allows you to set up matching rules and add, delete, replace, etc. to the matched structure in ast.

Getting started

Execute go run ./example to see the example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mapper

type Mapper struct {
	Matcher
	Replacer
}

func MCleanRawText

func MCleanRawText() Mapper

func MMoveAllHeaderLevel

func MMoveAllHeaderLevel(matcher Matcher, move int, max int) Mapper

func NewMapper

func NewMapper(matcher Matcher, replacer Replacer) Mapper

func NewRemover

func NewRemover(matcher Matcher) Mapper

type Matcher

type Matcher func(source []byte, node ast.Node) bool

type Modifier

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

func CreateModifierBySourceAndNode

func CreateModifierBySourceAndNode(md goldmark.Markdown, source []byte, node ast.Node) (*Modifier, error)

func CreateNodeAndModifierBySource

func CreateNodeAndModifierBySource(md goldmark.Markdown, source []byte) (*Modifier, error)

func (*Modifier) CreateSubNodeAndModifier

func (mod *Modifier) CreateSubNodeAndModifier(source []byte) (*Modifier, error)

func (*Modifier) CreateSubNodeModifier

func (mod *Modifier) CreateSubNodeModifier(node ast.Node) (*Modifier, error)

func (*Modifier) Dump

func (mod *Modifier) Dump()

func (*Modifier) Markdown

func (mod *Modifier) Markdown() goldmark.Markdown

func (*Modifier) Node

func (mod *Modifier) Node() ast.Node

func (*Modifier) Render

func (mod *Modifier) Render(w io.Writer) error

func (*Modifier) ReplaceNode

func (mod *Modifier) ReplaceNode(rs ...Mapper) error

func (*Modifier) Root

func (mod *Modifier) Root() *Modifier

func (*Modifier) Source

func (mod *Modifier) Source() []byte

func (*Modifier) WarpText

func (mod *Modifier) WarpText(source string) ast.Node

func (*Modifier) WrapNode

func (mod *Modifier) WrapNode(source []byte) (ast.Node, error)

type Replacer

type Replacer func(source []byte, node ast.Node) []ast.Node

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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