mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-03 15:37:17 -04:00
Make document indentable
This commit is contained in:
+46
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user