File tree 1 file changed +10
-7
lines changed
aztec/src/main/kotlin/org/wordpress/aztec/spans
1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -17,19 +17,22 @@ class MarkSpan : CharacterStyle, IAztecInlineSpan {
17
17
18
18
val color = CssStyleFormatter .getStyleAttribute(attributes,
19
19
CssStyleFormatter .CSS_COLOR_ATTRIBUTE )
20
- textColorValue = if (color.isNotEmpty()) {
21
- Color .parseColor(color)
22
- } else {
23
- null
24
- }
20
+ textColorValue = safelyParseColor(color)
25
21
}
26
22
27
23
constructor (attributes: AztecAttributes = AztecAttributes (), colorString: String? ) : super () {
28
24
this .attributes = attributes
25
+ textColorValue = safelyParseColor(colorString)
26
+ }
29
27
30
- textColorValue = if (colorString != null ) {
28
+ private fun safelyParseColor (colorString : String? ): Int? {
29
+ if (colorString == null ) {
30
+ return null
31
+ }
32
+ return try {
31
33
Color .parseColor(colorString)
32
- } else {
34
+ } catch (e: IllegalArgumentException ) {
35
+ // Unknown color
33
36
null
34
37
}
35
38
}
You can’t perform that action at this time.
0 commit comments