Skip to content

Commit

Permalink
Merge pull request #8 from serhatbolsu/main
Browse files Browse the repository at this point in the history
Support for Markdown
  • Loading branch information
NuPlay authored Jul 10, 2022
2 parents fdb152f + 7167f0a commit d140b40
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Sources/ExpandableText/ExpandableText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import SwiftUI
public struct ExpandableText: View {
var text : String

@available(iOS 15, *)
var markdownText: AttributedString {
(try? AttributedString(markdown: text, options: AttributedString.MarkdownParsingOptions(interpretedSyntax: .inlineOnlyPreservingWhitespace))) ?? AttributedString()
}

var font: Font = .body
var lineLimit: Int = 3
var foregroundColor: Color = .primary
Expand All @@ -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)
Expand Down

0 comments on commit d140b40

Please sign in to comment.