Use a Renderer interface instead of rendering fragments

This commit is contained in:
Christian Muehlhaeuser
2019-11-26 03:24:56 +01:00
parent d438c26548
commit 24a6306e1a
10 changed files with 469 additions and 397 deletions
+29
View File
@@ -0,0 +1,29 @@
package gold
import (
"io"
"strings"
bf "gopkg.in/russross/blackfriday.v2"
)
type ItemElement struct {
}
func (e *ItemElement) Render(w io.Writer, node *bf.Node, tr *TermRenderer) error {
l := 0
n := node
for n.Parent != nil && (n.Parent.Type == bf.List || n.Parent.Type == bf.Item) {
if n.Parent.Type == bf.List {
l++
}
n = n.Parent
}
el := &BaseElement{
Pre: strings.Repeat(" ", l-1) + "• ",
Token: string(node.Literal),
Style: Item,
}
return el.Render(w, node, tr)
}