notionast

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2025 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package notionast provides a set of functions to work with Notion AST It is used to convert notion.Blocks to AST and vice versa It also provides Walk functionality to traverse the AST.

Index

Constants

View Source
const RootNodeID = "tmp-0000000000"

RootNodeID is a constant for the root node auto-generated ID

Variables

This section is empty.

Functions

func ASTToBlocks

func ASTToBlocks(n *NodeBlock) notion.Blocks

ASTToBlocks converts the AST to notion.Blocks

func PrintAST

func PrintAST(node Node, levelArg ...int)

PrintAST prints the AST in a tree-like format

func Walk

func Walk(node Node, fn func(node Node))

Walk traverses the AST and calls the given function for each node

Types

type Node

type Node interface {
	GetID() NodeID
	GetType() NodeType

	GetPrevSibling() Node
	GetNextSibling() Node

	GetChildCount() int
	GetFirstChild() Node
	GetLastChild() Node
	GetParent() Node

	AppendChild(child Node)
	RemoveChild(child Node)
	RemoveChildren() // removes all children
}

Node is a generic interface for a node in the AST

type NodeBlock

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

NodeBlock is a node implementation for notion.Block

func BlocksToAST

func BlocksToAST(blocks notion.Blocks, parentArg ...*NodeBlock) *NodeBlock

BlocksToAST creates a new AST from the given notion.Blocks

func NewNodeBlock

func NewNodeBlock(block notion.Block, parent *NodeBlock) *NodeBlock

NewNodeBlock returns a new NodeBlock with the given block

func (*NodeBlock) AppendChild

func (n *NodeBlock) AppendChild(newNode Node)

AppendChild appends a child node to the end of the list of children.

func (*NodeBlock) GetBlock

func (n *NodeBlock) GetBlock() notion.Block

GetBlock returns the block of the node.

func (*NodeBlock) GetChildCount

func (n *NodeBlock) GetChildCount() int

GetChildCount returns the number of child nodes.

func (*NodeBlock) GetFirstChild

func (n *NodeBlock) GetFirstChild() Node

GetFirstChild returns the first child node, or nil if there are no children.

func (*NodeBlock) GetID

func (n *NodeBlock) GetID() NodeID

GetID returns the ID of the node.d

func (*NodeBlock) GetLastChild

func (n *NodeBlock) GetLastChild() Node

GetLastChild returns the last child node, or nil if there are no children.

func (*NodeBlock) GetNextSibling

func (n *NodeBlock) GetNextSibling() Node

GetNextSibling returns the next sibling node, or nil if there is none.

func (*NodeBlock) GetParent

func (n *NodeBlock) GetParent() Node

GetParent returns the parent node, or nil if the node has no parent.

func (*NodeBlock) GetPrevSibling

func (n *NodeBlock) GetPrevSibling() Node

GetPrevSibling returns the previous sibling node, or nil if there is none.

func (*NodeBlock) GetType

func (n *NodeBlock) GetType() NodeType

GetType returns the type of the node.

func (*NodeBlock) IsRoot

func (n *NodeBlock) IsRoot() bool

IsRoot returns true if the node is the root node

func (*NodeBlock) RemoveChild

func (n *NodeBlock) RemoveChild(childNode Node)

RemoveChild removes a child node (matched by ID) from the node.

func (*NodeBlock) RemoveChildren

func (n *NodeBlock) RemoveChildren()

RemoveChildren removes all child nodes from the node.

type NodeID

type NodeID string

NodeID is a unique identifier for a node

func (NodeID) String added in v0.0.2

func (n NodeID) String() string

type NodeType

type NodeType string

NodeType is a type of a node (It's considered to map to a block type)

func (NodeType) String added in v0.0.2

func (n NodeType) String() string

type Nodes

type Nodes []Node

Nodes is a slice of Node

Jump to

Keyboard shortcuts

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