mirror of https://github.com/usememos/memos
feat: implement restore nodes
parent
2a6f054876
commit
46f7cffc7b
@ -0,0 +1,14 @@
|
|||||||
|
package restore
|
||||||
|
|
||||||
|
import "github.com/usememos/memos/plugin/gomark/ast"
|
||||||
|
|
||||||
|
func Restore(nodes []ast.Node) string {
|
||||||
|
var result string
|
||||||
|
for _, node := range nodes {
|
||||||
|
if node == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
result += node.Restore()
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package restore
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/usememos/memos/plugin/gomark/ast"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRestore(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
nodes []ast.Node
|
||||||
|
rawText string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
nodes: nil,
|
||||||
|
rawText: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nodes: []ast.Node{
|
||||||
|
&ast.Text{
|
||||||
|
Content: "Hello world!",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rawText: "Hello world!",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nodes: []ast.Node{
|
||||||
|
&ast.Paragraph{
|
||||||
|
Children: []ast.Node{
|
||||||
|
&ast.Text{
|
||||||
|
Content: "Here: ",
|
||||||
|
},
|
||||||
|
&ast.Code{
|
||||||
|
Content: "Hello world!",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rawText: "Here: `Hello world!`",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
require.Equal(t, Restore(test.nodes), test.rawText)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue