transform

package
v0.0.0-...-32d4dcf Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterTransformer

func RegisterTransformer(name string, f func() Applier)

RegisterTransformer registers a new step type.

Types

type Applier

type Applier interface {
	Apply(prosemirror.Node) (prosemirror.Node, error)
	json.UnmarshalerV1
	json.MarshalerV1
}

Applier is an interface that all step types implement.

To register a new step type, you need to call RegisterTransformer with the step type and a function that returns a new instance of the step type.

type BaseStep

type BaseStep struct {
	Type string `json:"stepType"`
	From int    `json:"from"`
	To   int    `json:"to"`
}

type MarkStep

type MarkStep struct {
	BaseStep
	Mark prosemirror.Mark `json:"mark"`
	// contains filtered or unexported fields
}

func NewAddMarkStep

func NewAddMarkStep(from, to int, mark prosemirror.Mark) *MarkStep

func NewRemoveMarkStep

func NewRemoveMarkStep(from, to int, mark prosemirror.Mark) *MarkStep

func (*MarkStep) Apply

func (s *MarkStep) Apply(doc prosemirror.Node) (prosemirror.Node, error)

func (*MarkStep) MarshalJSON

func (s *MarkStep) MarshalJSON() ([]byte, error)

func (*MarkStep) String

func (s *MarkStep) String() string

func (*MarkStep) UnmarshalJSON

func (s *MarkStep) UnmarshalJSON(data []byte) error

type ReplaceAroundStep

type ReplaceAroundStep struct {
	BaseStep
	GapFrom   int               `json:"gapFrom"`
	GapTo     int               `json:"gapTo"`
	Insert    int               `json:"insert"`
	Slice     prosemirror.Slice `json:"slice"`
	Structure bool              `json:"structure"`
}

func (*ReplaceAroundStep) Apply

func (*ReplaceAroundStep) MarshalJSON

func (s *ReplaceAroundStep) MarshalJSON() ([]byte, error)

func (*ReplaceAroundStep) UnmarshalJSON

func (s *ReplaceAroundStep) UnmarshalJSON(data []byte) error

type ReplaceStep

type ReplaceStep struct {
	BaseStep
	Slice     prosemirror.Slice `json:"slice"`
	Structure bool              `json:"structure,omitempty"`
}

func (*ReplaceStep) Apply

func (s *ReplaceStep) Apply(doc prosemirror.Node) (prosemirror.Node, error)

func (*ReplaceStep) MarshalJSON

func (s *ReplaceStep) MarshalJSON() ([]byte, error)

func (*ReplaceStep) UnmarshalJSON

func (s *ReplaceStep) UnmarshalJSON(data []byte) error

type Step

type Step struct {
	Impl Applier
}

Step is an abstract type that gets implemented by the various step types that we have. This is so that we can unmarshal the step without knowing what type it is, and then we can use the type to apply the step.

func NewStep

func NewStep(a Applier) Step

NewStep returns a new step from the given applier.

func (*Step) Apply

func (s *Step) Apply(n prosemirror.Node) (prosemirror.Node, error)

func (*Step) MarshalJSON

func (s *Step) MarshalJSON() ([]byte, error)

func (*Step) UnmarshalJSON

func (s *Step) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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