Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: remove unused methods

Steven3edce174d640
diff --git a/plugin/gomark/ast/node.go b/plugin/gomark/ast/node.go
index 1877c38e2..4a7acad77 100644
--- a/plugin/gomark/ast/node.go
+++ b/plugin/gomark/ast/node.go
@@ -8,29 +8,17 @@ type Node interface {
// This method is used for debugging.
String() string
- // GetParent returns a parent node of this node.
- GetParent() Node
-
// GetPrevSibling returns a previous sibling node of this node.
GetPrevSibling() Node
// GetNextSibling returns a next sibling node of this node.
GetNextSibling() Node
- // GetChildren returns children nodes of this node.
- GetChildren() []Node
-
- // SetParent sets a parent node to this node.
- SetParent(Node)
-
// SetPrevSibling sets a previous sibling node to this node.
SetPrevSibling(Node)
// SetNextSibling sets a next sibling node to this node.
SetNextSibling(Node)
-
- // SetChildren sets children nodes to this node.
- SetChildren([]Node)
}
type NodeType int
@@ -49,17 +37,9 @@ func NewNodeType(name string) NodeType {
}
type BaseNode struct {
- parent Node
-
prevSibling Node
nextSibling Node
-
- children []Node
-}
-
-func (n *BaseNode) GetParent() Node {
- return n.parent
}
func (n *BaseNode) GetPrevSibling() Node {
@@ -70,14 +50,6 @@ func (n *BaseNode) GetNextSibling() Node {
return n.nextSibling
}
-func (n *BaseNode) GetChildren() []Node {
- return n.children
-}
-
-func (n *BaseNode) SetParent(node Node) {
- n.parent = node
-}
-
func (n *BaseNode) SetPrevSibling(node Node) {
n.prevSibling = node
}
@@ -85,7 +57,3 @@ func (n *BaseNode) SetPrevSibling(node Node) {
func (n *BaseNode) SetNextSibling(node Node) {
n.nextSibling = node
}
-
-func (n *BaseNode) SetChildren(nodes []Node) {
- n.children = nodes
-}
diff --git a/plugin/gomark/parser/blockquote.go b/plugin/gomark/parser/blockquote.go
index a0d8b0c73..240c0de2f 100644
--- a/plugin/gomark/parser/blockquote.go
+++ b/plugin/gomark/parser/blockquote.go
@@ -42,11 +42,11 @@ func (p *BlockquoteParser) Parse(tokens []*tokenizer.Token) (ast.Node, error) {
}
contentTokens := tokens[2:size]
- blockquote := &ast.Blockquote{}
- children, err := ParseInline(blockquote, contentTokens)
+ children, err := ParseInline(contentTokens)
if err != nil {
return nil, err
}
- blockquote.Children = children
- return blockquote, nil
+ return &ast.Blockquote{
+ Children: children,
+ }, nil
}
diff --git a/plugin/gomark/parser/heading.go b/plugin/gomark/parser/heading.go
index 8613af02a..1b228dbf4 100644
--- a/plugin/gomark/parser/heading.go
+++ b/plugin/gomark/parser/heading.go
@@ -65,13 +65,12 @@ func (p *HeadingParser) Parse(tokens []*tokenizer.Token) (ast.Node, error) {
}
contentTokens := tokens[level+1 : size]
- heading := &ast.Heading{
- Level: level,
- }
- children, err := ParseInline(heading, contentTokens)
+ children, err := ParseInline(contentTokens)
if err != nil {
return nil, err
}
- heading.Children = children
- return heading, nil
+ return &ast.Heading{
+ Level: level,
+ Children: children,
+ }, nil
}
diff --git a/plugin/gomark/parser/paragraph.go b/plugin/gomark/parser/paragraph.go
index a40c99621..c5edeb168 100644
--- a/plugin/gomark/parser/paragraph.go
+++ b/plugin/gomark/parser/paragraph.go
@@ -39,11 +39,11 @@ func (p *ParagraphParser) Parse(tokens []*tokenizer.Token) (ast.Node, error) {
}
contentTokens := tokens[:size]
- paragraph := &ast.Paragraph{}
- children, err := ParseInline(paragraph, contentTokens)
+ children, err := ParseInline(contentTokens)
if err != nil {
return nil, err
}
- paragraph.Children = children
- return paragraph, nil
+ return &ast.Paragraph{
+ Children: children,
+ }, nil
}
diff --git a/plugin/gomark/parser/parser.go b/plugin/gomark/parser/parser.go
index 33f602e3f..9d48852c1 100644
--- a/plugin/gomark/parser/parser.go
+++ b/plugin/gomark/parser/parser.go
@@ -73,7 +73,7 @@ var defaultInlineParsers = []InlineParser{
NewTextParser(),
}
-func ParseInline(parent ast.Node, tokens []*tokenizer.Token) ([]ast.Node, error) {
+func ParseInline(tokens []*tokenizer.Token) ([]ast.Node, error) {
nodes := []ast.Node{}
var prevNode ast.Node
for len(tokens) > 0 {
@@ -86,8 +86,8 @@ func ParseInline(parent ast.Node, tokens []*tokenizer.Token) ([]ast.Node, error)
}
tokens = tokens[size:]
- node.SetParent(parent)
if prevNode != nil {
+ // Merge text nodes if possible.
if prevNode.Type() == ast.NodeTypeText && node.Type() == ast.NodeTypeText {
prevNode.(*ast.Text).Content += node.(*ast.Text).Content
break
@@ -96,13 +96,11 @@ func ParseInline(parent ast.Node, tokens []*tokenizer.Token) ([]ast.Node, error)
prevNode.SetNextSibling(node)
node.SetPrevSibling(prevNode)
}
-
nodes = append(nodes, node)
prevNode = node
break
}
}
}
- parent.SetChildren(nodes)
return nodes, nil
}