Commit 7bc631fb21

7bc631fb211533378a9f710b8eb963108619de79

parent: 7724ce8809

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-22 20:50 UTC

Quick Look: read files that aren't UTF-8 as Latin-1

Ref #224

Layout: unified · split

Sources/OrgstarQuickLook/PreviewProvider.swift +3 −1
@@ -10,7 +10,9 @@ import QuickLook
10@objc(PreviewProvider) 10@objc(PreviewProvider)
11final class PreviewProvider: QLPreviewProvider, QLPreviewingController { 11final class PreviewProvider: QLPreviewProvider, QLPreviewingController {
12 func providePreview(for request: QLFilePreviewRequest) async throws -> QLPreviewReply { 12 func providePreview(for request: QLFilePreviewRequest) async throws -> QLPreviewReply {
13 let text = try String(contentsOf: request.fileURL, encoding: .utf8) 13 // Latin-1 maps every byte, so a file that isn't UTF-8 still shows.
14 let data = try Data(contentsOf: request.fileURL)
15 let text = String(data: data, encoding: .utf8) ?? String(data: data, encoding: .isoLatin1) ?? ""
14 let title = request.fileURL.deletingPathExtension().lastPathComponent 16 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) 17 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) } 18 return QLPreviewReply(dataOfContentType: .html, contentSize: CGSize(width: 800, height: 800)) { _ in Data(html.utf8) }
docs/manual/guide/15-alongside-emacs.org +1 −1
@@ -153,7 +153,7 @@ An app started from the Dock doesn't see your shell's =PATH=, which is why orgst
153 153
154* Quick Look 154* Quick Look
155 155
156orgstar includes a Quick Look extension for org files (=.org= and =.org_archive=). Pressing Space on an org file in Finder, or in the Files app on iOS, shows the file as the HTML export renders it, with its =#+SETUPFILE= keywords applied. The preview reads only UTF-8 files. 156orgstar includes a Quick Look extension for org files (=.org= and =.org_archive=). Pressing Space on an org file in Finder, or in the Files app on iOS, shows the file as the HTML export renders it, with its =#+SETUPFILE= keywords applied. The preview reads a file as UTF-8, or as Latin-1 when it isn't valid UTF-8.
157 157
158Inside orgstar, selecting a file in the sidebar that isn't text shows a Quick Look preview, with Open with Default App and Show in Finder below it. 158Inside orgstar, selecting a file in the sidebar that isn't text shows a Quick Look preview, with Open with Default App and Show in Finder below it.
159 159