Commit 3f4fa24f74
Verified · cmc
Layout: unified · split
Sources/OrgApp/AppStoreCommands.swift +1 −1
| @@ -4,7 +4,7 @@ import Foundation | ||
| 4 | 4 | /// Emacs, and attaching by link, which the sandbox doesn't allow. |
| 5 | 5 | public enum AppStoreCommands { |
| 6 | 6 | public static let hidden: Set<String> = [ |
| 7 | "app.export.pdf", "app.export.odt", "app.export.text", | |
| 7 | "app.export.pdf", "app.export.text", | |
| 8 | 8 | "app.attach.link", "app.attach.symlink", |
| 9 | 9 | ] |
| 10 | 10 | |
Sources/OrgApp/CommandTitles.swift +1 −1
| @@ -90,7 +90,7 @@ enum CommandTitles { | ||
| 90 | 90 | String(localized: "Export to HTML and Open", comment: "Command title"), |
| 91 | 91 | String(localized: "Export to LaTeX", comment: "Command title"), |
| 92 | 92 | String(localized: "Export to Markdown", comment: "Command title"), |
| 93 | String(localized: "Export to ODT with Emacs", comment: "Command title"), | |
| 93 | String(localized: "Export to ODT", comment: "Command title"), | |
| 94 | 94 | String(localized: "Export to PDF", comment: "Command title"), |
| 95 | 95 | String(localized: "Export to PDF with Emacs", comment: "Command title"), |
| 96 | 96 | String(localized: "Export to Plain Text", comment: "Command title"), |
Sources/OrgApp/Publish.swift +11 −5
| @@ -14,8 +14,8 @@ import OrgCore | ||
| 14 | 14 | /// |
| 15 | 15 | /// Other keys: `base-extension` (an Emacs regexp, or `any`), `exclude` (a regexp on the path |
| 16 | 16 | /// under the base directory), `include` (file names separated by spaces), `publishing-function` |
| 17 | /// (`org-html-publish-to-html`, `org-md-publish-to-md`, `org-publish-attachment`, separated by | |
| 18 | /// spaces), `sitemap-filename`, `sitemap-title`, `sitemap-style` (`tree` or `list`), | |
| 17 | /// (`org-html-publish-to-html`, `org-md-publish-to-md`, `org-odt-publish-to-odt`, | |
| 18 | /// `org-publish-attachment`, separated by spaces), `sitemap-filename`, `sitemap-title`, `sitemap-style` (`tree` or `list`), | |
| 19 | 19 | /// `sitemap-sort-files` (`alphabetically`, `chronologically`, `anti-chronologically`, `nil`), |
| 20 | 20 | /// `sitemap-sort-folders` (`ignore`, `first`, `last`, `nil`), `sitemap-ignore-case`, |
| 21 | 21 | /// `body-only`, and `components` (project names separated by spaces) for a project of projects. |
| @@ -40,7 +40,7 @@ public struct PublishProject: Sendable, Equatable { | ||
| 40 | 40 | |
| 41 | 41 | public init(name: String) { self.name = name } |
| 42 | 42 | |
| 43 | public static let functions = ["org-html-publish-to-html", "org-md-publish-to-md", "org-latex-publish-to-latex", "org-publish-attachment"] | |
| 43 | public static let functions = ["org-html-publish-to-html", "org-md-publish-to-md", "org-latex-publish-to-latex", "org-odt-publish-to-odt", "org-publish-attachment"] | |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | public enum Publish { |
| @@ -290,13 +290,14 @@ public enum Publish { | ||
| 290 | 290 | if directory((file as NSString).deletingLastPathComponent) == outputDirectory { return nil } |
| 291 | 291 | return outputDirectory + (file as NSString).lastPathComponent |
| 292 | 292 | } |
| 293 | let ext = ["org-md-publish-to-md": "md", "org-latex-publish-to-latex": "tex"][function] ?? "html" | |
| 293 | let ext = ["org-md-publish-to-md": "md", "org-latex-publish-to-latex": "tex", "org-odt-publish-to-odt": "odt"][function] ?? "html" | |
| 294 | 294 | guard let text = read(file) else { throw Failure(description: "Can't read \(file)") } |
| 295 | 295 | return ExportScope.output(for: URL(fileURLWithPath: outputDirectory + (file as NSString).lastPathComponent), |
| 296 | 296 | name: ExportScope.fileName(text), extension: ext).path |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | /// Copies an attachment to `output`, or writes what `function` exports from `file`. | |
| 299 | /// Copies an attachment to `output`, or writes what `function` exports from `file`; ODT is | |
| 300 | /// exported here, with the preferences' settings. | |
| 300 | 301 | private static func write( |
| 301 | 302 | _ file: String, to output: String, function: String, bodyOnly: Bool, |
| 302 | 303 | read: (String) -> String?, export: (_ function: String, _ text: String, _ path: String, _ bodyOnly: Bool) throws -> String |
| @@ -305,6 +306,11 @@ public enum Publish { | ||
| 305 | 306 | if function == "org-publish-attachment" { |
| 306 | 307 | if fm.fileExists(atPath: output) { try fm.removeItem(atPath: output) } |
| 307 | 308 | try fm.copyItem(atPath: file, toPath: output) |
| 309 | } else if function == "org-odt-publish-to-odt" { | |
| 310 | let text = read(file) ?? "" | |
| 311 | let settings = OrgPreferences.orgSettings().resolvingSetupFiles(in: text, path: file, read: OrgSettings.readFile) | |
| 312 | try ODTExport.document(text, settings: settings, path: file, author: NSFullUserName(), language: OrgPreferences.exportLanguage()) | |
| 313 | .write(to: URL(fileURLWithPath: output), options: .atomic) | |
| 308 | 314 | } else { |
| 309 | 315 | try export(function, read(file) ?? "", file, bodyOnly).write(toFile: output, atomically: true, encoding: .utf8) |
| 310 | 316 | } |
Sources/OrgEditorAppKit/EditorCommands.swift +1 −1
| @@ -174,7 +174,7 @@ public enum EditorCommands { | ||
| 174 | 174 | EditorCommand(id: "app.export.plain-text", title: "Export to Plain Text", action: .app), |
| 175 | 175 | EditorCommand(id: "app.copy-rich-text", title: "Copy as Rich Text", action: .app), |
| 176 | 176 | EditorCommand(id: "app.export.pdf", title: "Export to PDF with Emacs", action: .app), |
| 177 | EditorCommand(id: "app.export.odt", title: "Export to ODT with Emacs", action: .app), | |
| 177 | EditorCommand(id: "app.export.odt", title: "Export to ODT", action: .app), | |
| 178 | 178 | EditorCommand(id: "app.export.latex", title: "Export to LaTeX", action: .app), |
| 179 | 179 | EditorCommand(id: "app.export.text", title: "Export to Plain Text with Emacs", action: .app), |
| 180 | 180 | EditorCommand(id: "app.export.icalendar", title: "Export to iCalendar", action: .app), |
Sources/Orgstar/ContentView.swift +15 −1
| @@ -630,6 +630,20 @@ struct ContentView: View { | ||
| 630 | 630 | } |
| 631 | 631 | case "latex" where exportLaTeX(text, whole: whole, url: url, to: destination, open: open, subtree: subtree ? caret : nil, bodyOnly: bodyOnly, settings: defaults): |
| 632 | 632 | break |
| 633 | case "odt": | |
| 634 | let name = ExportScope.fileName(whole, subtreeAt: subtree ? caret : nil, settings: defaults) | |
| 635 | guard let target = destination ?? writable(ExportScope.output(for: url, name: name, extension: "odt")) else { return } | |
| 636 | // A missing image stops the export, so offer access to them first. | |
| 637 | _ = reach(ODTExport.imageFiles(text, settings: defaults, path: path).filter(WorkspaceModel.isThere)) | |
| 638 | do { | |
| 639 | let data = try ODTExport.document(text, settings: defaults, path: path, author: NSFullUserName(), language: OrgPreferences.exportLanguage()) | |
| 640 | try FileManager.default.createDirectory(at: target.deletingLastPathComponent(), withIntermediateDirectories: true) | |
| 641 | try data.write(to: target, options: .atomic) | |
| 642 | commands.show("Exported to \(target.lastPathComponent)") | |
| 643 | if open { NSWorkspace.shared.open(target) } | |
| 644 | } catch { | |
| 645 | commands.show("Can't export \(target.lastPathComponent): \(error.localizedDescription)") | |
| 646 | } | |
| 633 | 647 | case "print-pdf", "docx", "rtf", "plain-text": |
| 634 | 648 | let ext = ["print-pdf": "pdf", "plain-text": "txt"][format] ?? format |
| 635 | 649 | let name = ExportScope.fileName(whole, subtreeAt: subtree ? caret : nil, settings: defaults) |
| @@ -661,7 +675,7 @@ struct ContentView: View { | ||
| 661 | 675 | } |
| 662 | 676 | default: |
| 663 | 677 | #if !APPSTORE |
| 664 | let functions = ["pdf": "org-latex-export-to-pdf", "odt": "org-odt-export-to-odt", "latex": "org-latex-export-to-latex", "text": "org-ascii-export-to-ascii"] | |
| 678 | let functions = ["pdf": "org-latex-export-to-pdf", "latex": "org-latex-export-to-latex", "text": "org-ascii-export-to-ascii"] | |
| 665 | 679 | guard let function = functions[format] else { return } |
| 666 | 680 | commands.show("Exporting with Emacs…") |
| 667 | 681 | commands.runInEmacs { |
Sources/Orgstar/ExportSheet.swift +3 −3
| @@ -24,14 +24,14 @@ struct ExportSheet: View { | ||
| 24 | 24 | #if APPSTORE |
| 25 | 25 | static let formats: [(id: String, title: String, ext: String)] = [ |
| 26 | 26 | ("html", "HTML", "html"), ("markdown", "Markdown", "md"), ("print-pdf", "PDF", "pdf"), ("docx", "Word", "docx"), |
| 27 | ("rtf", "Rich Text (RTF)", "rtf"), ("plain-text", "Plain text", "txt"), ("icalendar", "iCalendar", "ics"), | |
| 28 | ("latex", "LaTeX", "tex"), | |
| 27 | ("rtf", "Rich Text (RTF)", "rtf"), ("plain-text", "Plain text", "txt"), ("odt", "ODT", "odt"), | |
| 28 | ("icalendar", "iCalendar", "ics"), ("latex", "LaTeX", "tex"), | |
| 29 | 29 | ] |
| 30 | 30 | #else |
| 31 | 31 | static let formats: [(id: String, title: String, ext: String)] = [ |
| 32 | 32 | ("html", "HTML", "html"), ("markdown", "Markdown", "md"), ("print-pdf", "PDF", "pdf"), ("docx", "Word", "docx"), |
| 33 | 33 | ("rtf", "Rich Text (RTF)", "rtf"), ("plain-text", "Plain text", "txt"), ("pdf", "PDF via LaTeX (Emacs)", "pdf"), |
| 34 | ("odt", "ODT (Emacs)", "odt"), ("latex", "LaTeX", "tex"), ("text", "Plain text, ASCII (Emacs)", "txt"), | |
| 34 | ("odt", "ODT", "odt"), ("latex", "LaTeX", "tex"), ("text", "Plain text, ASCII (Emacs)", "txt"), | |
| 35 | 35 | ("icalendar", "iCalendar", "ics"), |
| 36 | 36 | ] |
| 37 | 37 | #endif |
Sources/OrgstarMobile/ExportMenu.swift +11 −4
| @@ -6,11 +6,11 @@ import OrgPresentation | ||
| 6 | 6 | import SwiftUI |
| 7 | 7 | import UniformTypeIdentifiers |
| 8 | 8 | |
| 9 | /// A file exported as HTML, Markdown, PDF, Word, RTF, plain text, iCalendar or LaTeX, written when the | |
| 10 | /// share sheet takes it. | |
| 9 | /// A file exported as HTML, Markdown, PDF, Word, RTF, plain text, ODT, iCalendar or LaTeX, written | |
| 10 | /// when the share sheet takes it. | |
| 11 | 11 | struct OrgExport: Transferable { |
| 12 | 12 | enum Format: CaseIterable { |
| 13 | case html, markdown, pdf, docx, rtf, plainText, icalendar | |
| 13 | case html, markdown, pdf, docx, rtf, plainText, odt, icalendar | |
| 14 | 14 | case latex |
| 15 | 15 | |
| 16 | 16 | /// Whether it needs Pro now: every format but HTML and Markdown, until Pro is unlocked. |
| @@ -24,6 +24,7 @@ struct OrgExport: Transferable { | ||
| 24 | 24 | case .docx: "Word" |
| 25 | 25 | case .rtf: "Rich Text (RTF)" |
| 26 | 26 | case .plainText: "Plain Text" |
| 27 | case .odt: "ODT" | |
| 27 | 28 | case .icalendar: "iCalendar" |
| 28 | 29 | case .latex: "LaTeX" |
| 29 | 30 | } |
| @@ -37,6 +38,7 @@ struct OrgExport: Transferable { | ||
| 37 | 38 | case .docx: "docx" |
| 38 | 39 | case .rtf: "rtf" |
| 39 | 40 | case .plainText: "txt" |
| 41 | case .odt: "odt" | |
| 40 | 42 | case .icalendar: "ics" |
| 41 | 43 | case .latex: "tex" |
| 42 | 44 | } |
| @@ -77,6 +79,8 @@ struct OrgExport: Transferable { | ||
| 77 | 79 | .exportingCondition { $0.format == .rtf } |
| 78 | 80 | FileRepresentation(exportedContentType: .plainText) { try await $0.write() } |
| 79 | 81 | .exportingCondition { $0.format == .plainText } |
| 82 | FileRepresentation(exportedContentType: UTType(filenameExtension: "odt") ?? .data) { try await $0.write() } | |
| 83 | .exportingCondition { $0.format == .odt } | |
| 80 | 84 | FileRepresentation(exportedContentType: .calendarEvent) { try await $0.write() } |
| 81 | 85 | .exportingCondition { $0.format == .icalendar } |
| 82 | 86 | FileRepresentation(exportedContentType: UTType(filenameExtension: "tex") ?? .plainText) { try await $0.write() } |
| @@ -106,6 +110,9 @@ struct OrgExport: Transferable { | ||
| 106 | 110 | throw error |
| 107 | 111 | } |
| 108 | 112 | try content.write(to: url, atomically: true, encoding: .utf8) |
| 113 | case .odt: | |
| 114 | try ODTExport.document(text, settings: settings, path: path, author: NSFullUserName(), language: OrgPreferences.exportLanguage()) | |
| 115 | .write(to: url, options: .atomic) | |
| 109 | 116 | case .icalendar: |
| 110 | 117 | try ICalendarFiles.export(self.text, path: path, settings: settings, options: OrgPreferences.icalendarOptions(), |
| 111 | 118 | subtree: subtree, destination: url) |
| @@ -126,7 +133,7 @@ struct OrgExport: Transferable { | ||
| 126 | 133 | } |
| 127 | 134 | } |
| 128 | 135 | |
| 129 | /// Sharing the file as HTML, Markdown, PDF, Word, RTF, plain text, iCalendar or LaTeX: to another app, or saved with | |
| 136 | /// Sharing the file as HTML, Markdown, PDF, Word, RTF, plain text, ODT, iCalendar or LaTeX: to another app, or saved with | |
| 130 | 137 | /// Save to Files; or copying it as rich text. |
| 131 | 138 | struct ExportMenu: View { |
| 132 | 139 | let path: String |
Tests/OrgAppTests/PublishTests.swift +16
| @@ -195,6 +195,22 @@ struct PublishTests { | ||
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | /// `org-odt-publish-to-odt` writes `.odt` files, which the export closure doesn't see. | |
| 199 | @Test func publishesODT() throws { | |
| 200 | let folder = FileManager.default.temporaryDirectory.appendingPathComponent("orgstar-publish-\(UUID().uuidString)") | |
| 201 | defer { try? FileManager.default.removeItem(at: folder) } | |
| 202 | try Self.tree(folder) | |
| 203 | let config = "[[publish]]\nname = \"odt\"\nbase-directory = \"\(folder.path)/src\"\npublishing-directory = \"\(folder.path)/odt\"\npublishing-function = \"org-odt-publish-to-odt\"\n" | |
| 204 | let loaded = Publish.projects(fromConfig: config, root: nil) | |
| 205 | #expect(loaded.problems.isEmpty) | |
| 206 | let read = { (path: String) in try? String(contentsOfFile: path, encoding: .utf8) } | |
| 207 | let report = try Publish.publish(loaded.projects, all: loaded.projects, read: read) { _, _, _, _ in Issue.record("exported as text"); return "" } | |
| 208 | #expect(report.published.count == 3) | |
| 209 | let data = try Data(contentsOf: folder.appendingPathComponent("odt/a.odt")) | |
| 210 | #expect(data.prefix(4) == Data([0x50, 0x4b, 0x03, 0x04])) | |
| 211 | #expect(String(decoding: data[30..<38], as: UTF8.self) == "mimetype") | |
| 212 | } | |
| 213 | ||
| 198 | 214 | @Test func skipsUpToDateFilesAndFindsProjects() throws { |
| 199 | 215 | let folder = FileManager.default.temporaryDirectory.appendingPathComponent("orgstar-publish-\(UUID().uuidString)").resolvingSymlinksInPath() |
| 200 | 216 | defer { try? FileManager.default.removeItem(at: folder) } |
l10n/Localizable.xcstrings +6 −6
| @@ -11714,37 +11714,37 @@ | ||
| 11714 | 11714 | } |
| 11715 | 11715 | } |
| 11716 | 11716 | }, |
| 11717 | "Export to ODT with Emacs": { | |
| 11717 | "Export to ODT": { | |
| 11718 | 11718 | "comment": "Command title", |
| 11719 | 11719 | "localizations": { |
| 11720 | 11720 | "de": { |
| 11721 | 11721 | "stringUnit": { |
| 11722 | 11722 | "state": "translated", |
| 11723 | "value": "Mit Emacs als ODT exportieren" | |
| 11723 | "value": "Als ODT exportieren" | |
| 11724 | 11724 | } |
| 11725 | 11725 | }, |
| 11726 | 11726 | "es": { |
| 11727 | 11727 | "stringUnit": { |
| 11728 | 11728 | "state": "translated", |
| 11729 | "value": "Exportar a ODT con Emacs" | |
| 11729 | "value": "Exportar a ODT" | |
| 11730 | 11730 | } |
| 11731 | 11731 | }, |
| 11732 | 11732 | "fr": { |
| 11733 | 11733 | "stringUnit": { |
| 11734 | 11734 | "state": "translated", |
| 11735 | "value": "Exporter en ODT avec Emacs" | |
| 11735 | "value": "Exporter en ODT" | |
| 11736 | 11736 | } |
| 11737 | 11737 | }, |
| 11738 | 11738 | "ja": { |
| 11739 | 11739 | "stringUnit": { |
| 11740 | 11740 | "state": "translated", |
| 11741 | "value": "EmacsでODTに書き出す" | |
| 11741 | "value": "ODTに書き出す" | |
| 11742 | 11742 | } |
| 11743 | 11743 | }, |
| 11744 | 11744 | "pt-BR": { |
| 11745 | 11745 | "stringUnit": { |
| 11746 | 11746 | "state": "translated", |
| 11747 | "value": "Exportar para ODT com o Emacs" | |
| 11747 | "value": "Exportar para ODT" | |
| 11748 | 11748 | } |
| 11749 | 11749 | } |
| 11750 | 11750 | } |