Skip to content

Commit

Permalink
Merge branch 'dev' into sjmarf/app-icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjmarf committed Jan 4, 2024
2 parents 7523297 + b8060a7 commit 6051cf1
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions Mlem/Views/Shared/Markdown View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ struct MarkdownBlock: Identifiable {
}

struct MarkdownView: View {
@State private var text: String
@State private var blocks: [MarkdownBlock] = []
private let text: String
private let blocks: [MarkdownBlock]

private let isNsfw: Bool
private let replaceImagesWithEmoji: Bool
Expand All @@ -235,13 +235,12 @@ struct MarkdownView: View {
isInline: Bool = false,
alignment: TextAlignment = .leading
) {
_text = isInline
? .init(wrappedValue: MarkdownView.prepareInlineMarkdown(text: text))
: .init(wrappedValue: text)
self.text = isInline ? MarkdownView.prepareInlineMarkdown(text: text) : text
self.isNsfw = isNsfw
self.replaceImagesWithEmoji = replaceImagesWithEmoji
self.isInline = isInline
self.alignment = alignment
self.blocks = MarkdownView.parseMarkdownForImages(text: text)
}

var body: some View {
Expand All @@ -259,9 +258,6 @@ struct MarkdownView: View {
}
}
}
.task {
blocks = parseMarkdownForImages(text: text)
}
}

private var theme: Theme {
Expand All @@ -275,7 +271,7 @@ struct MarkdownView: View {
.replacingOccurrences(of: "\\s+", with: " ", options: .regularExpression)
}

func parseMarkdownForImages(text: String) -> [MarkdownBlock] {
static func parseMarkdownForImages(text: String) -> [MarkdownBlock] {
// this regex will capture the '![label](url "title") pattern so we can handle it separately
// piece by piece:
// !\[(?'label'[^\]]*)\] matches '![label]' and captures 'label' as label
Expand Down

0 comments on commit 6051cf1

Please sign in to comment.