Sources/OrgstarQuickLook/PreviewProvider.swift

64cf820baaa28ffc1584f14cf4c10dd6281f3bd8
orgstar/Sources/OrgstarQuickLook/PreviewProvider.swift

18 lines · 876 bytes

 1import Foundation
 2import OrgCore
 3#if canImport(QuickLookUI)
 4import QuickLookUI
 5#else
 6import QuickLook
 7#endif
 8
 9/// Quick Look's preview of an org file: the file as the HTML export renders it.
10@objc(PreviewProvider)
11final class PreviewProvider: QLPreviewProvider, QLPreviewingController {
12    func providePreview(for request: QLFilePreviewRequest) async throws -> QLPreviewReply {
13        let text = try String(contentsOf: request.fileURL, encoding: .utf8)
14        let title = request.fileURL.deletingPathExtension().lastPathComponent
15        let html = HTMLExport.page(text, fallbackTitle: title, settings: OrgSettings.default.resolvingSetupFiles(in: text, path: request.fileURL.path, read: OrgSettings.readFile), path: request.fileURL.path)
16        return QLPreviewReply(dataOfContentType: .html, contentSize: CGSize(width: 800, height: 800)) { _ in Data(html.utf8) }
17    }
18}
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