Skip to content

Commit ba3140b

Browse files
committed
Add support for macCatalyst
1 parent 0de1bbe commit ba3140b

File tree

5 files changed

+12
-59
lines changed

5 files changed

+12
-59
lines changed

Examples/MarkdownUIDemo/MarkdownUIDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ let package = Package(
3434
.package(
3535
name: "AttributedText",
3636
url: "https://github.com/gonzalezreal/AttributedText",
37-
from: "0.2.1"
37+
from: "0.2.2"
3838
),
3939
.package(
4040
name: "NetworkImage",

Sources/MarkdownUI/Shared/Markdown.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if canImport(SwiftUI) && !os(watchOS) && !targetEnvironment(macCatalyst)
1+
#if canImport(SwiftUI) && !os(watchOS)
22

33
import AttributedText
44
import CommonMark
@@ -63,8 +63,7 @@
6363
layoutDirection: layoutDirection,
6464
multilineTextAlignment: multilineTextAlignment
6565
),
66-
style: markdownStyle,
67-
isSynchronous: false
66+
style: markdownStyle
6867
)
6968
}
7069
}
@@ -78,16 +77,14 @@
7877
baseURL: URL?,
7978
writingDirection: NSWritingDirection,
8079
alignment: NSTextAlignment,
81-
style: MarkdownStyle,
82-
isSynchronous: Bool
80+
style: MarkdownStyle
8381
) {
8482
renderer = MarkdownRenderer(
8583
document: document,
8684
baseURL: baseURL,
8785
writingDirection: writingDirection,
8886
alignment: alignment,
89-
style: style,
90-
environment: isSynchronous ? .synchronous : .default
87+
style: style
9188
)
9289
}
9390

Sources/MarkdownUI/Shared/MarkdownRenderer.swift

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
scheduler: DispatchQueue.main.eraseToAnyScheduler()
2121
)
2222

23-
static let synchronous = Environment(
24-
textAttachments: syncTextAttachments(for:baseURL:),
25-
scheduler: DispatchQueue.immediateScheduler.eraseToAnyScheduler()
26-
)
27-
2823
let textAttachments: (Set<String>, URL?) -> AnyPublisher<[String: NSTextAttachment], Never>
2924
let scheduler: AnySchedulerOf<DispatchQueue>
3025
}
@@ -37,7 +32,7 @@
3732
writingDirection: NSWritingDirection,
3833
alignment: NSTextAlignment,
3934
style: MarkdownStyle,
40-
environment: Environment
35+
environment: Environment = .default
4136
) {
4237
attributedString = NSAttributedString(
4338
document: document,
@@ -94,43 +89,4 @@
9489
.eraseToAnyPublisher()
9590
}
9691

97-
@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)
98-
private func syncTextAttachments(
99-
for urls: Set<String>,
100-
baseURL: URL?
101-
) -> AnyPublisher<[String: NSTextAttachment], Never> {
102-
let attachmentURLs = urls.compactMap {
103-
URL(string: $0, relativeTo: baseURL)
104-
}
105-
106-
guard !attachmentURLs.isEmpty else {
107-
return Just([:]).eraseToAnyPublisher()
108-
}
109-
110-
var result: [String: NSTextAttachment] = [:]
111-
112-
for url in attachmentURLs {
113-
guard let data = try? Data(contentsOf: url),
114-
let image = image(from: data) else { continue }
115-
116-
let attachment = ImageAttachment()
117-
attachment.image = image
118-
119-
result[url.relativeString] = attachment
120-
}
121-
122-
return Just(result).eraseToAnyPublisher()
123-
}
124-
125-
#if os(macOS)
126-
private func image(from data: Data) -> NSImage? {
127-
NSImage(data: data)
128-
}
129-
130-
#elseif canImport(UIKit)
131-
private func image(from data: Data) -> UIImage? {
132-
UIImage(data: data, scale: UIScreen.main.scale)
133-
}
134-
#endif
135-
13692
#endif

0 commit comments

Comments
 (0)