-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
Added the if url.isFileURL {... } code so that local images (also with relative path and baseURL = file:://) do work. Feel free to add it to the main branch.
extension DefaultNetworkImageLoader: NetworkImageLoader {
public func image(from url: URL) async throws -> CGImage {
if let image = self.cache.image(for: url) {
return image
}
if url.isFileURL {
let data = try Data(contentsOf: url)
guard let source = CGImageSourceCreateWithData(data as CFData, nil),
let image = CGImageSourceCreateImageAtIndex(
source, 0, [kCGImageSourceShouldCache: true] as CFDictionary
) else {
throw URLError(.cannotDecodeContentData)
}
// add image to cache
self.cache.setImage(image, for: url)
return image
}
...
Thanks for NetworkImage and swift-markdown-ui.
I use them in a macOS project for a low-code IDE to support documentation.
gonzalezreal
Metadata
Metadata
Assignees
Labels
No labels