-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathdump_structure.go
50 lines (43 loc) · 884 Bytes
/
dump_structure.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package notionapi
import (
"bytes"
"fmt"
"io"
)
type writer struct {
level int
w io.Writer
}
func (w *writer) writeString(s string) {
_, _ = io.WriteString(w.w, s)
}
func (w *writer) writeLevel() {
for n := 0; n < w.level; n++ {
w.writeString(" ")
}
}
func (w *writer) block(block *Block) {
if block == nil {
return
}
w.writeLevel()
s := fmt.Sprintf("%s %s alive=%v\n", block.Type, block.ID, block.Alive)
w.writeString(s)
w.level++
for _, child := range block.Content {
w.block(child)
}
w.level--
}
// Dump writes a simple representation of Page to w. A debugging helper.
func Dump(w io.Writer, page *Page) {
wr := writer{w: w}
wr.block(page.Root())
}
// DumpToString returns a simple representation of Page as a string.
// A debugging helper.
func DumpToString(page *Page) string {
buf := &bytes.Buffer{}
Dump(buf, page)
return buf.String()
}