Sources/OrgstarQuickLook/PreviewProvider.swift

ed6e31776e956b9ee4d2e06de012dd6e01c8eb75
orgstar/Sources/OrgstarQuickLook/PreviewProvider.swift

14 lines · 702 bytes

 1import Foundation
 2import OrgCore
 3import QuickLookUI
 4
 5/// Quick Look's preview of an org file: the file as the HTML export renders it.
 6@objc(PreviewProvider)
 7final class PreviewProvider: QLPreviewProvider, QLPreviewingController {
 8    func providePreview(for request: QLFilePreviewRequest) async throws -> QLPreviewReply {
 9        let text = try String(contentsOf: request.fileURL, encoding: .utf8)
10        let title = request.fileURL.deletingPathExtension().lastPathComponent
11        let html = HTMLExport.page(text, fallbackTitle: title, path: request.fileURL.path)
12        return QLPreviewReply(dataOfContentType: .html, contentSize: CGSize(width: 800, height: 800)) { _ in Data(html.utf8) }
13    }
14}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form