From 34bce244cabb60d318794a62e599cb9aebc31b0c Mon Sep 17 00:00:00 2001 From: Mikhail Barashkov Date: Wed, 22 Sep 2021 13:00:24 +0300 Subject: [PATCH] Support color in style attribute in HTML elements --- .../Support/XMLDynamicAttributesResolver.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sources/SwiftRichString/Support/XMLDynamicAttributesResolver.swift b/Sources/SwiftRichString/Support/XMLDynamicAttributesResolver.swift index 9a8a7a2..c885d6e 100644 --- a/Sources/SwiftRichString/Support/XMLDynamicAttributesResolver.swift +++ b/Sources/SwiftRichString/Support/XMLDynamicAttributesResolver.swift @@ -96,6 +96,18 @@ open class StandardXMLAttributesResolver: XMLDynamicAttributesResolver { let finalStyleToApply = Style() xmlStyle.enumerateAttributes { key, value in switch key { + case "style": + let styles = value.split(separator: ";") + for style in styles { + let styleElements = style.split(separator: ":") + if styleElements.count == 2 { + if styleElements[0] == "color" { + finalStyleToApply.color = Color(hexString: String(styleElements[1])) + break + } + } + } + case "color": // color support finalStyleToApply.color = Color(hexString: value)