render markdown preview in the file browser

This commit is contained in:
Ian Gulliver
2026-10-18 11:48:53 -07:00
parent aac7cfe858
commit 4f9823129d
4 changed files with 37 additions and 8 deletions
+3 -1
View File
@@ -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