Children in a Document or Paragraph element inherit their parent's color styles

This commit is contained in:
Christian Muehlhaeuser
2019-12-02 15:23:45 +01:00
parent bbd7dfecce
commit d0b616b12b
4 changed files with 10 additions and 5 deletions
+1 -1
View File
@@ -68,7 +68,7 @@ func (e *BaseElement) Render(w io.Writer, node *bf.Node, tr *TermRenderer) error
}
}()
rules := tr.style[e.Style]
rules := cascadeStyles(tr.blockStyle, tr.style[e.Style])
if rules == nil {
_, _ = w.Write([]byte(e.Token))
return nil
+2
View File
@@ -12,6 +12,7 @@ type DocumentElement struct {
func (e *DocumentElement) Render(w io.Writer, node *bf.Node, tr *TermRenderer) error {
rules := tr.style[Document]
if rules != nil {
tr.blockStyle.Push(rules)
if rules.Prefix != "" {
renderText(w, rules, rules.Prefix)
}
@@ -38,6 +39,7 @@ func (e *DocumentElement) Finish(w io.Writer, node *bf.Node, tr *TermRenderer) e
return err
}
tr.document.Reset()
tr.blockStyle.Pop()
if suffix != "" {
renderText(iw, rules, suffix)
+5 -4
View File
@@ -22,10 +22,11 @@ type TermRenderer struct {
BaseURL string
WordWrap int
style map[StyleType]*ElementStyle
document bytes.Buffer
paragraph *bytes.Buffer
table TableElement
style map[StyleType]*ElementStyle
document bytes.Buffer
paragraph *bytes.Buffer
blockStyle StyleStack
table TableElement
}
func Render(in string, stylePath string) ([]byte, error) {
+2
View File
@@ -23,6 +23,7 @@ func (e *ParagraphElement) Render(w io.Writer, node *bf.Node, tr *TermRenderer)
if rules == nil {
_, _ = w.Write([]byte(pre))
} else {
tr.blockStyle.Push(rules)
renderText(w, rules, pre)
if rules.Prefix != "" {
@@ -52,5 +53,6 @@ func (e *ParagraphElement) Finish(w io.Writer, node *bf.Node, tr *TermRenderer)
_, err := iw.Write(reflow.ReflowBytes(tr.paragraph.Bytes(), tr.WordWrap-int(indent)))
tr.paragraph.Reset()
tr.paragraph = nil
tr.blockStyle.Pop()
return err
}