From ca06d9968c20b28607d27fb0ef933df53ef3168f Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 4 Dec 2019 06:38:10 +0100 Subject: [PATCH] Add StyleStack.Parent, returning the current style's parent --- style.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/style.go b/style.go index 59e4546..46a1189 100644 --- a/style.go +++ b/style.go @@ -83,6 +83,14 @@ func (s StyleStack) Indent() uint { return i } +func (s StyleStack) Parent() *ElementStyle { + if len(s) < 2 { + return s.Current() + } + + return cascadeStyles(s[0:len(s)-2], s[len(s)-2]) +} + func (s StyleStack) Current() *ElementStyle { if len(s) == 0 { return nil