util.go 714 B

123456789101112131415161718192021222324
  1. package premailer
  2. import (
  3. "github.com/vanng822/css"
  4. )
  5. func copyRule(selector string, rule *css.CSSRule) *css.CSSRule {
  6. // copy rule for each selector
  7. styles := make([]*css.CSSStyleDeclaration, 0)
  8. for _, s := range rule.Style.Styles {
  9. styles = append(styles, css.NewCSSStyleDeclaration(s.Property, s.Value.Text(), s.Important))
  10. }
  11. copiedStyle := css.CSSStyleRule{Selector: css.NewCSSValueString(selector), Styles: styles}
  12. copiedRule := &css.CSSRule{Type: rule.Type, Style: copiedStyle}
  13. return copiedRule
  14. }
  15. func makeRuleImportant(rule *css.CSSRule) string {
  16. // this for using Text() which has nice sorted props
  17. for _, s := range rule.Style.Styles {
  18. s.Important = true
  19. }
  20. return rule.Style.Text()
  21. }