render markdown preview in the file browser
This commit is contained in:
@@ -12,7 +12,7 @@ private let dataImage = Re(#"^data:image/(png|jpeg|gif|webp);"#, caseless: true)
|
||||
private let fileURL = Re(#"^file://"#, caseless: true)
|
||||
private let anyScheme = Re(#"^[a-z][a-z0-9+.-]*:"#, caseless: true)
|
||||
|
||||
func worktreeImageSource(_ path: String, _ taskId: String?) -> ImageSource? {
|
||||
func worktreeImageSource(_ path: String, _ taskId: String?, dir: String = "") -> ImageSource? {
|
||||
if dataImage.test(path) {
|
||||
guard let comma = path.firstIndex(of: ","), path[..<comma].lowercased().hasSuffix(";base64"), let data = Data(base64Encoded: String(path[path.index(after: comma)...])) else {
|
||||
return nil
|
||||
@@ -27,6 +27,8 @@ func worktreeImageSource(_ path: String, _ taskId: String?) -> ImageSource? {
|
||||
file = decoded
|
||||
} else if anyScheme.test(file) {
|
||||
return nil
|
||||
} else if !dir.isEmpty && !file.hasPrefix("/") {
|
||||
file = "\(dir)/\(file)"
|
||||
}
|
||||
guard let taskId else {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user