From 75fbe0df03bcdd5e3e05ccd3ff3dfa91562a1901 Mon Sep 17 00:00:00 2001 From: Serhat Bolsu Date: Fri, 1 Jul 2022 23:26:02 +0400 Subject: [PATCH 1/2] Support for Markdown --- Sources/ExpandableText/ExpandableText.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sources/ExpandableText/ExpandableText.swift b/Sources/ExpandableText/ExpandableText.swift index b39a733..e083c61 100644 --- a/Sources/ExpandableText/ExpandableText.swift +++ b/Sources/ExpandableText/ExpandableText.swift @@ -10,6 +10,11 @@ import SwiftUI public struct ExpandableText: View { var text : String + @available(iOS 15, *) + var markdownText: AttributedString { + (try? AttributedString(markdown: text)) ?? AttributedString() + } + var font: Font = .body var lineLimit: Int = 3 var foregroundColor: Color = .primary @@ -28,7 +33,13 @@ public struct ExpandableText: View { } public var body: some View { ZStack(alignment: .bottomTrailing){ - Text(text) + Group { + if #available(iOS 15.0, *) { + Text(markdownText) + } else { + Text(text) + } + } .font(font) .foregroundColor(foregroundColor) .lineLimit(expand == true ? nil : lineLimit) From 7167f0a3f0cdc92f675f0022e6f71521dff347aa Mon Sep 17 00:00:00 2001 From: Serhat Bolsu Date: Fri, 1 Jul 2022 23:30:07 +0400 Subject: [PATCH 2/2] Markdown with new line support[D --- Sources/ExpandableText/ExpandableText.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ExpandableText/ExpandableText.swift b/Sources/ExpandableText/ExpandableText.swift index e083c61..5055ef3 100644 --- a/Sources/ExpandableText/ExpandableText.swift +++ b/Sources/ExpandableText/ExpandableText.swift @@ -12,7 +12,7 @@ public struct ExpandableText: View { @available(iOS 15, *) var markdownText: AttributedString { - (try? AttributedString(markdown: text)) ?? AttributedString() + (try? AttributedString(markdown: text, options: AttributedString.MarkdownParsingOptions(interpretedSyntax: .inlineOnlyPreservingWhitespace))) ?? AttributedString() } var font: Font = .body