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}