From 4de66af8a0b7ed6195dc9d22a8905367997942bb Mon Sep 17 00:00:00 2001 From: Lanius Trolling Date: Sat, 6 Apr 2024 10:26:35 -0400 Subject: [PATCH] Extract method --- .../kotlin/info/mechyrdia/lore/parser_html.kt | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) 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", -- 2.25.1