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
+25
View File
@@ -225,6 +225,9 @@ private struct FilesBody: View {
} else if let c = model.content {
if c.binary {
EmptyText(text: "Binary file.")
} else if model.place.file?.lowercased().hasSuffix(".md") == true {
FileMarkdown(content: c, taskId: store.selectedTaskId, dir: model.place.dir)
.id(model.generation)
} else {
FileText(content: c)
.id(model.generation)
@@ -308,6 +311,28 @@ private struct EntryRow: View {
}
}
private struct FileMarkdown: View {
let content: FileContent
let taskId: String?
let dir: String
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 0) {
MarkdownView(blocks: parseMarkdown(content.text), ctx: MDContext(taskId: taskId, dir: dir))
if content.truncated {
Text("Showing the first \(bytes(shown(content))) of \(bytes(content.size)).")
.foregroundStyle(Palette.muted)
.padding(.top, 12)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, 16)
.padding(.vertical, 10)
}
}
}
private struct FileText: View {
let content: FileContent