render markdown preview in the file browser
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user