Sources/OrgApp/HTMLPreview.swift

d24a6c5c43d3e63039ff8395d03b8399ecede125
orgstar/Sources/OrgApp/HTMLPreview.swift

15 lines · 876 bytes

 1import Foundation
 2
 3/// Export to HTML and Open where the page is shown from a temporary file (iOS, in Quick Look):
 4/// the images go in the page, as nothing is beside it there.
 5public enum HTMLPreview {
 6    /// Writes `html` (an `HTMLExport.page`) as `name` in a new temporary folder. `directory` is
 7    /// the Org file's folder, where relative image links are read from.
 8    public static func write(_ html: String, directory: URL?, name: String) throws -> URL {
 9        let folder = FileManager.default.temporaryDirectory.appendingPathComponent("orgstar-html-\(UUID().uuidString)")
10        try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)
11        let url = folder.appendingPathComponent(name)
12        try PDFExport.inliningImages(html, directory: directory).write(to: url, atomically: true, encoding: .utf8)
13        return url
14    }
15}
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