Extract method
authorLanius Trolling <lanius@laniustrolling.dev>
Sat, 6 Apr 2024 14:26:35 +0000 (10:26 -0400)
committerLanius Trolling <lanius@laniustrolling.dev>
Sat, 6 Apr 2024 14:26:35 +0000 (10:26 -0400)
src/jvmMain/kotlin/info/mechyrdia/lore/parser_html.kt

index 1008810ce24cf39ef26a138e948dab449a30b80b..06a91bf0542434624c05949e2058c01ce0aee7bc 100644 (file)
@@ -286,19 +286,24 @@ class HtmlHeaderLexerTag(val tagCreator: TagCreator, val anchor: (ParserTree) ->
        }
 }
 
-fun processColor(param: String?): Map<String, String> = param?.removePrefix("#")?.let { colorRaw ->
-       when (colorRaw.length) {
-               6 -> colorRaw
-               3 -> {
-                       val (r, g, b) = colorRaw.toCharArray()
-                       "$r$r$g$g$b$b"
-               }
-               
-               else -> null
+fun repeatColorDigits(color: String) = when (color.length) {
+       6 -> color
+       3 -> {
+               val (r, g, b) = color.toCharArray()
+               "$r$r$g$g$b$b"
        }
-}?.toIntOrNull(16)?.toString(16)?.padStart(6, '0')?.let {
-       mapOf("style" to "color:#$it")
-}.orEmpty()
+       
+       else -> null
+}
+
+fun processColor(param: String?): Map<String, String> = param
+       ?.removePrefix("#")
+       ?.let(::repeatColorDigits)
+       ?.toIntOrNull(16)
+       ?.toString(16)
+       ?.padStart(6, '0')
+       ?.let { mapOf("style" to "color:#$it") }
+       .orEmpty()
 
 private val VALID_ALIGNMENTS = mapOf(
        "left" to "text-align:left",