slate

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsElementNode

func IsElementNode(value interface{}) bool

IsElementNode checks if a value is a Slate.js element node

func IsTextNode

func IsTextNode(value interface{}) bool

IsTextNode checks if a value is a Slate.js text node

func MergeElementNodesFromMaps

func MergeElementNodesFromMaps(one, two map[string]interface{}) map[string]interface{}

MergeElementNodesFromMaps merges two Slate element nodes from maps (backward compatibility)

func MergeTextNodesFromMaps

func MergeTextNodesFromMaps(one, two map[string]interface{}) map[string]interface{}

MergeTextNodesFromMaps merges two Slate text nodes from maps (backward compatibility)

func SplitElementNodeFromMap

func SplitElementNodeFromMap(nodeMap map[string]interface{}, pos int, props map[string]interface{}) []map[string]interface{}

SplitElementNodeFromMap splits a Slate element node from map (backward compatibility)

func SplitTextNodeFromMap

func SplitTextNodeFromMap(nodeMap map[string]interface{}, pos int, props map[string]interface{}) []map[string]interface{}

SplitTextNodeFromMap splits a Slate text node from map (backward compatibility)

Types

type SlateElementNode

type SlateElementNode = SlateNode

SlateElementNode is a type alias for better API clarity

type SlateNode

type SlateNode struct {
	// Text field is present only for text nodes
	Text *string `json:"text,omitempty"`
	// Children field is present only for element nodes
	Children []SlateNode `json:"children,omitempty"`
	// Properties contains additional properties (equivalent to [key: string]: unknown)
	Properties map[string]interface{} `json:",inline"`
}

SlateNode represents a Slate.js node that can be either a text node or an element node. It uses a union-type approach similar to TypeScript's SlateNode.

func FromMap

func FromMap(data map[string]interface{}) *SlateNode

FromMap creates a SlateNode from map[string]interface{} for backward compatibility

func MergeElementNodes

func MergeElementNodes(one, two *SlateNode) *SlateNode

MergeElementNodes merges two Slate element nodes by concatenating their children and merging properties

func MergeTextNodes

func MergeTextNodes(one, two *SlateNode) *SlateNode

MergeTextNodes merges two Slate text nodes by concatenating their text and merging properties

func NewElementNode

func NewElementNode(children []SlateNode, properties map[string]interface{}) *SlateNode

NewElementNode creates a new Slate element node

func NewTextNode

func NewTextNode(text string, properties map[string]interface{}) *SlateNode

NewTextNode creates a new Slate text node

func SplitElementNode

func SplitElementNode(node *SlateNode, pos int, props map[string]interface{}) []*SlateNode

SplitElementNode splits a Slate element node at the specified position in its children

func SplitTextNode

func SplitTextNode(node *SlateNode, pos int, props map[string]interface{}) []*SlateNode

SplitTextNode splits a Slate text node at the specified position

func (*SlateNode) GetChildren

func (n *SlateNode) GetChildren() []SlateNode

GetChildren returns the children (empty slice if not an element node)

func (*SlateNode) GetProperty

func (n *SlateNode) GetProperty(key string) interface{}

GetProperty returns a property value

func (*SlateNode) GetText

func (n *SlateNode) GetText() string

GetText returns the text content (empty string if not a text node)

func (*SlateNode) IsElement

func (n *SlateNode) IsElement() bool

IsElement returns true if this is an element node

func (*SlateNode) IsText

func (n *SlateNode) IsText() bool

IsText returns true if this is a text node

func (*SlateNode) SetChildren

func (n *SlateNode) SetChildren(children []SlateNode)

SetChildren sets the children and converts to element node

func (*SlateNode) SetProperty

func (n *SlateNode) SetProperty(key string, value interface{})

SetProperty sets a property value

func (*SlateNode) SetText

func (n *SlateNode) SetText(text string)

SetText sets the text content and converts to text node

func (*SlateNode) ToMap

func (n *SlateNode) ToMap() map[string]interface{}

ToMap converts the node to map[string]interface{} for backward compatibility

type SlateTextNode

type SlateTextNode = SlateNode

SlateTextNode is a type alias for better API clarity

Jump to

Keyboard shortcuts

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