mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-06 00:47:15 -04:00
Support margin style flag
This commit is contained in:
+11
-3
@@ -26,21 +26,29 @@ func (e *DocumentElement) Finish(w io.Writer, node *bf.Node, tr *TermRenderer) e
|
|||||||
indent = rules.Indent
|
indent = rules.Indent
|
||||||
suffix = rules.Suffix
|
suffix = rules.Suffix
|
||||||
}
|
}
|
||||||
|
pw := &PaddingWriter{
|
||||||
|
Padding: uint(tr.WordWrap + int(indent*2)),
|
||||||
|
PadFunc: func(wr io.Writer) {
|
||||||
|
renderText(w, rules, " ")
|
||||||
|
},
|
||||||
|
Forward: &AnsiWriter{
|
||||||
|
Forward: w,
|
||||||
|
},
|
||||||
|
}
|
||||||
iw := &IndentWriter{
|
iw := &IndentWriter{
|
||||||
Indent: indent,
|
Indent: indent,
|
||||||
Forward: &AnsiWriter{
|
Forward: &AnsiWriter{
|
||||||
Forward: w,
|
Forward: pw,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err := iw.Write(tr.document.Bytes())
|
_, err := iw.Write(tr.document.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
renderText(iw, rules, suffix)
|
||||||
|
|
||||||
tr.document.Reset()
|
tr.document.Reset()
|
||||||
tr.blockStyle.Pop()
|
tr.blockStyle.Pop()
|
||||||
|
|
||||||
renderText(w, rules, suffix)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ type ElementStyle struct {
|
|||||||
Inverse bool `json:"inverse"`
|
Inverse bool `json:"inverse"`
|
||||||
Blink bool `json:"blink"`
|
Blink bool `json:"blink"`
|
||||||
Indent uint `json:"indent"`
|
Indent uint `json:"indent"`
|
||||||
|
Margin uint `json:"margin"`
|
||||||
Theme string `json:"theme"`
|
Theme string `json:"theme"`
|
||||||
Prefix string `json:"prefix"`
|
Prefix string `json:"prefix"`
|
||||||
Suffix string `json:"suffix"`
|
Suffix string `json:"suffix"`
|
||||||
@@ -83,6 +84,19 @@ func (s StyleStack) Indent() uint {
|
|||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s StyleStack) Margin() uint {
|
||||||
|
var i uint
|
||||||
|
|
||||||
|
for _, v := range s {
|
||||||
|
if v == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
i += v.Margin
|
||||||
|
}
|
||||||
|
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
func (s StyleStack) Parent() *ElementStyle {
|
func (s StyleStack) Parent() *ElementStyle {
|
||||||
if len(s) < 2 {
|
if len(s) < 2 {
|
||||||
return s.Current()
|
return s.Current()
|
||||||
|
|||||||
Reference in New Issue
Block a user