1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-11-11 01:42:35 +03:00

Merge pull request #181 from exyte/qfix/fix-style-parsing-method

Refactor and fix css style parser in SVG parser
This commit is contained in:
Yuriy Kashnikov 2017-10-03 17:21:09 +07:00 committed by GitHub
commit 3b10a4735b

View File

@ -104,16 +104,20 @@ open class SVGParser {
if let rawStyle = styleNode.element?.text {
var styleAttributes: [String: String] = [:]
let parts = rawStyle.trimmingCharacters(in: .whitespacesAndNewlines).split(separator: "{")
let className = String(parts[0].dropFirst())
let style = parts[1].dropLast()
let styleParts = style.replacingOccurrences(of: " ", with: "").components(separatedBy: ";")
styleParts.forEach { styleAttribute in
let currentStyle = styleAttribute.components(separatedBy: ":")
if currentStyle.count == 2 {
styleAttributes.updateValue(currentStyle[1], forKey: currentStyle[0])
if parts.count == 2 {
let className = String(parts[0].dropFirst())
if !className.isEmpty {
let style = String(parts[1].dropLast())
let styleParts = style.replacingOccurrences(of: " ", with: "").components(separatedBy: ";")
styleParts.forEach { styleAttribute in
let currentStyle = styleAttribute.components(separatedBy: ":")
if currentStyle.count == 2 {
styleAttributes.updateValue(currentStyle[1], forKey: currentStyle[0])
}
}
styleTable[className] = styleAttributes
}
}
styleTable[className] = styleAttributes
}
}