Skip to content

Commit d140b40

Browse files
authored
Merge pull request #8 from serhatbolsu/main
Support for Markdown
2 parents fdb152f + 7167f0a commit d140b40

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Sources/ExpandableText/ExpandableText.swift

+12-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import SwiftUI
1010
public struct ExpandableText: View {
1111
var text : String
1212

13+
@available(iOS 15, *)
14+
var markdownText: AttributedString {
15+
(try? AttributedString(markdown: text, options: AttributedString.MarkdownParsingOptions(interpretedSyntax: .inlineOnlyPreservingWhitespace))) ?? AttributedString()
16+
}
17+
1318
var font: Font = .body
1419
var lineLimit: Int = 3
1520
var foregroundColor: Color = .primary
@@ -28,7 +33,13 @@ public struct ExpandableText: View {
2833
}
2934
public var body: some View {
3035
ZStack(alignment: .bottomTrailing){
31-
Text(text)
36+
Group {
37+
if #available(iOS 15.0, *) {
38+
Text(markdownText)
39+
} else {
40+
Text(text)
41+
}
42+
}
3243
.font(font)
3344
.foregroundColor(foregroundColor)
3445
.lineLimit(expand == true ? nil : lineLimit)

0 commit comments

Comments
 (0)