From 036ecf5b806daecd2e3de072e55b68bee09b8d82 Mon Sep 17 00:00:00 2001 From: Karan Sharma <55722391+ksharma-xyz@users.noreply.github.com> Date: Tue, 3 Dec 2024 16:54:26 +1100 Subject: [PATCH] iOS: Improve HTML text parsing and add iOS tests (#418) ### TL;DR Enhanced HTML text handling for iOS platform and added comprehensive unit tests. ### What changed? - Added error handling to iOS HTML text processing with `runCatching` - Improved HTML tag replacement by adding support for `` and `
  • ` tags - Added trim functionality to remove unnecessary whitespace - Created unit tests to verify HTML tag replacement functionality ### Why make this change? To improve the reliability of HTML text processing on iOS and ensure consistent text display across different HTML formats. The addition of unit tests provides confidence in the HTML parsing functionality and helps prevent regressions. --- .../krail/trip/planner/ui/alerts}/HtmlText.kt | 0 .../ui/src/iosMain/kotlin/HtmlText.kt | 30 --------- .../krail/trip/planner/ui/alerts/HtmlText.kt | 37 +++++++++++ .../trip/planner/ui/alerts/HtmlTextTest.kt | 63 +++++++++++++++++++ 4 files changed, 100 insertions(+), 30 deletions(-) rename feature/trip-planner/ui/src/androidMain/kotlin/{ => xyz/ksharma/krail/trip/planner/ui/alerts}/HtmlText.kt (100%) delete mode 100644 feature/trip-planner/ui/src/iosMain/kotlin/HtmlText.kt create mode 100644 feature/trip-planner/ui/src/iosMain/kotlin/xyz/ksharma/krail/trip/planner/ui/alerts/HtmlText.kt create mode 100644 feature/trip-planner/ui/src/iosTest/kotlin/xyz/ksharma/krail/trip/planner/ui/alerts/HtmlTextTest.kt diff --git a/feature/trip-planner/ui/src/androidMain/kotlin/HtmlText.kt b/feature/trip-planner/ui/src/androidMain/kotlin/xyz/ksharma/krail/trip/planner/ui/alerts/HtmlText.kt similarity index 100% rename from feature/trip-planner/ui/src/androidMain/kotlin/HtmlText.kt rename to feature/trip-planner/ui/src/androidMain/kotlin/xyz/ksharma/krail/trip/planner/ui/alerts/HtmlText.kt diff --git a/feature/trip-planner/ui/src/iosMain/kotlin/HtmlText.kt b/feature/trip-planner/ui/src/iosMain/kotlin/HtmlText.kt deleted file mode 100644 index 06f39210..00000000 --- a/feature/trip-planner/ui/src/iosMain/kotlin/HtmlText.kt +++ /dev/null @@ -1,30 +0,0 @@ -package xyz.ksharma.krail.trip.planner.ui.alerts - -import androidx.compose.foundation.clickable -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import xyz.ksharma.krail.taj.components.Text - -@Composable -actual fun HtmlText( - text: String, - modifier: Modifier, - onClick: () -> Unit, - color: Color, - urlColor: Color, -) { - Text(text = replaceHtmlTags(text), modifier = Modifier.clickable { onClick() }, color = color) -} - -// TODO - A workaround for iOS until https://issuetracker.google.com/issues/139326648 is fixed. -private fun replaceHtmlTags(html: String): String { - return html - .replace("", "\n") - .replace("
  • ", "\n") - .replace("", "\n") + .replace("
  • ", "") + .replace("