From 4d388713d0cfe490182bafe636db135645b8adb7 Mon Sep 17 00:00:00 2001 From: Saif Alhaider Date: Mon, 3 Feb 2025 22:34:00 +0300 Subject: [PATCH] fix: strikethrough doesn't render with underline --- .../markdown/annotator/AnnotatedStringKtx.kt | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/annotator/AnnotatedStringKtx.kt b/multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/annotator/AnnotatedStringKtx.kt index 2635f31e..1ab0abb9 100644 --- a/multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/annotator/AnnotatedStringKtx.kt +++ b/multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/annotator/AnnotatedStringKtx.kt @@ -133,18 +133,37 @@ fun AnnotatedString.Builder.appendMarkdownLink( return } val text = linkText.firstOrNull()?.getUnescapedTextInNode(content) - val destination = node.findChildOfType(MarkdownElementTypes.LINK_DESTINATION)?.getUnescapedTextInNode(content) - val linkLabel = node.findChildOfType(MarkdownElementTypes.LINK_LABEL)?.getUnescapedTextInNode(content) + val destination = + node.findChildOfType(MarkdownElementTypes.LINK_DESTINATION)?.getUnescapedTextInNode(content) + val linkLabel = + node.findChildOfType(MarkdownElementTypes.LINK_LABEL)?.getUnescapedTextInNode(content) val annotation = destination ?: linkLabel if (annotation != null) { - if (text != null) annotatorSettings.referenceLinkHandler?.store(text, annotation) - withLink(LinkAnnotation.Url(annotation, annotatorSettings.linkTextSpanStyle, annotatorSettings.linkInteractionListener)) { + text?.let { annotatorSettings.referenceLinkHandler?.store(it, annotation) } + + val linkStyle = if (node.parent?.type == GFMElementTypes.STRIKETHROUGH) { + annotatorSettings.linkTextSpanStyle.withUnderline() + } else { + annotatorSettings.linkTextSpanStyle + } + + withLink(LinkAnnotation.Url(annotation, linkStyle, annotatorSettings.linkInteractionListener)) { buildMarkdownAnnotatedString(content, linkText, annotatorSettings) } } else { buildMarkdownAnnotatedString(content, linkText, annotatorSettings) } + +} + +fun TextLinkStyles.withUnderline(): TextLinkStyles { + return TextLinkStyles( + style = style?.merge(SpanStyle(textDecoration = TextDecoration.LineThrough + TextDecoration.Underline)), + focusedStyle = focusedStyle, + hoveredStyle = hoveredStyle, + pressedStyle = pressedStyle + ) } /**