Make document indentable

This commit is contained in:
Christian Muehlhaeuser
2019-11-30 08:07:40 +01:00
parent fca5fd91d6
commit d6d52829bb
5 changed files with 80 additions and 18 deletions
+46
View File
@@ -0,0 +1,46 @@
package gold
import (
"io"
bf "gopkg.in/russross/blackfriday.v2"
)
type DocumentElement struct {
}
func (e *DocumentElement) Render(w io.Writer, node *bf.Node, tr *TermRenderer) error {
rules := tr.style[Document]
if rules != nil {
if rules.Prefix != "" {
renderText(w, rules, rules.Prefix)
}
}
return nil
}
func (e *DocumentElement) Finish(w io.Writer, node *bf.Node, tr *TermRenderer) error {
var indent uint
suffix := ""
rules := tr.style[Document]
if rules != nil {
indent = rules.Indent
suffix = rules.Suffix
}
iw := &IndentWriter{
Indent: indent,
Forward: w,
}
_, err := iw.Write(tr.document.Bytes())
if err != nil {
return err
}
tr.document.Reset()
if suffix != "" {
renderText(iw, rules, suffix)
}
return nil
}