From: Lanius Trolling Date: Sat, 6 Apr 2024 14:26:35 +0000 (-0400) Subject: Extract method X-Git-Url: https://gitweb.starshipfights.net/?a=commitdiff_plain;h=4de66af8a0b7ed6195dc9d22a8905367997942bb;p=factbooks Extract method --- diff --git a/src/jvmMain/kotlin/info/mechyrdia/lore/parser_html.kt b/src/jvmMain/kotlin/info/mechyrdia/lore/parser_html.kt index 1008810..06a91bf 100644 --- a/src/jvmMain/kotlin/info/mechyrdia/lore/parser_html.kt +++ b/src/jvmMain/kotlin/info/mechyrdia/lore/parser_html.kt @@ -286,19 +286,24 @@ class HtmlHeaderLexerTag(val tagCreator: TagCreator, val anchor: (ParserTree) -> } } -fun processColor(param: String?): Map = 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 = 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",