mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: implement restore nodes
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
package ast
|
||||
|
||||
import "fmt"
|
||||
|
||||
type BaseInline struct {
|
||||
BaseNode
|
||||
}
|
||||
@ -14,6 +16,10 @@ func (*Text) Type() NodeType {
|
||||
return TextNode
|
||||
}
|
||||
|
||||
func (n *Text) Restore() string {
|
||||
return n.Content
|
||||
}
|
||||
|
||||
type Bold struct {
|
||||
BaseInline
|
||||
|
||||
@ -26,6 +32,15 @@ func (*Bold) Type() NodeType {
|
||||
return BoldNode
|
||||
}
|
||||
|
||||
func (n *Bold) Restore() string {
|
||||
symbol := n.Symbol + n.Symbol
|
||||
children := ""
|
||||
for _, child := range n.Children {
|
||||
children += child.Restore()
|
||||
}
|
||||
return fmt.Sprintf("%s%s%s", symbol, children, symbol)
|
||||
}
|
||||
|
||||
type Italic struct {
|
||||
BaseInline
|
||||
|
||||
@ -38,6 +53,10 @@ func (*Italic) Type() NodeType {
|
||||
return ItalicNode
|
||||
}
|
||||
|
||||
func (n *Italic) Restore() string {
|
||||
return fmt.Sprintf("%s%s%s", n.Symbol, n.Content, n.Symbol)
|
||||
}
|
||||
|
||||
type BoldItalic struct {
|
||||
BaseInline
|
||||
|
||||
@ -50,6 +69,11 @@ func (*BoldItalic) Type() NodeType {
|
||||
return BoldItalicNode
|
||||
}
|
||||
|
||||
func (n *BoldItalic) Restore() string {
|
||||
symbol := n.Symbol + n.Symbol + n.Symbol
|
||||
return fmt.Sprintf("%s%s%s", symbol, n.Content, symbol)
|
||||
}
|
||||
|
||||
type Code struct {
|
||||
BaseInline
|
||||
|
||||
@ -60,6 +84,10 @@ func (*Code) Type() NodeType {
|
||||
return CodeNode
|
||||
}
|
||||
|
||||
func (n *Code) Restore() string {
|
||||
return fmt.Sprintf("`%s`", n.Content)
|
||||
}
|
||||
|
||||
type Image struct {
|
||||
BaseInline
|
||||
|
||||
@ -71,6 +99,10 @@ func (*Image) Type() NodeType {
|
||||
return ImageNode
|
||||
}
|
||||
|
||||
func (n *Image) Restore() string {
|
||||
return fmt.Sprintf("", n.AltText, n.URL)
|
||||
}
|
||||
|
||||
type Link struct {
|
||||
BaseInline
|
||||
|
||||
@ -82,16 +114,28 @@ func (*Link) Type() NodeType {
|
||||
return LinkNode
|
||||
}
|
||||
|
||||
func (n *Link) Restore() string {
|
||||
return fmt.Sprintf("[%s](%s)", n.Text, n.URL)
|
||||
}
|
||||
|
||||
type AutoLink struct {
|
||||
BaseInline
|
||||
|
||||
URL string
|
||||
URL string
|
||||
IsRawText bool
|
||||
}
|
||||
|
||||
func (*AutoLink) Type() NodeType {
|
||||
return AutoLinkNode
|
||||
}
|
||||
|
||||
func (n *AutoLink) Restore() string {
|
||||
if n.IsRawText {
|
||||
return n.URL
|
||||
}
|
||||
return fmt.Sprintf("<%s>", n.URL)
|
||||
}
|
||||
|
||||
type Tag struct {
|
||||
BaseInline
|
||||
|
||||
@ -102,6 +146,10 @@ func (*Tag) Type() NodeType {
|
||||
return TagNode
|
||||
}
|
||||
|
||||
func (n *Tag) Restore() string {
|
||||
return fmt.Sprintf("<%s>", n.Content)
|
||||
}
|
||||
|
||||
type Strikethrough struct {
|
||||
BaseInline
|
||||
|
||||
@ -112,6 +160,10 @@ func (*Strikethrough) Type() NodeType {
|
||||
return StrikethroughNode
|
||||
}
|
||||
|
||||
func (n *Strikethrough) Restore() string {
|
||||
return fmt.Sprintf("~~%s~~", n.Content)
|
||||
}
|
||||
|
||||
type EscapingCharacter struct {
|
||||
BaseInline
|
||||
|
||||
@ -121,3 +173,7 @@ type EscapingCharacter struct {
|
||||
func (*EscapingCharacter) Type() NodeType {
|
||||
return EscapingCharacterNode
|
||||
}
|
||||
|
||||
func (n *EscapingCharacter) Restore() string {
|
||||
return fmt.Sprintf("\\%s", n.Symbol)
|
||||
}
|
||||
|
Reference in New Issue
Block a user