Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions PeekMark.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
B99E3B7C4790DE780684B589 /* PreviewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewViewController.swift; sourceTree = "<group>"; };
D1032F275C06D493280925DD /* MarkdownPreviewWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkdownPreviewWindow.swift; sourceTree = "<group>"; };
D5930CEE95459D0E5F893402 /* MenuBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarView.swift; sourceTree = "<group>"; };
F11C727FD46CC04F24B2D70C /* QuickMarkCore */ = {isa = PBXFileReference; lastKnownFileType = folder; name = QuickMarkCore; path = QuickMarkCore; sourceTree = SOURCE_ROOT; };
F11C727FD46CC04F24B2D70C /* QuickMarkCore */ = {isa = PBXFileReference; lastKnownFileType = folder; path = QuickMarkCore; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -201,14 +201,6 @@
attributes = {
BuildIndependentTargetsInParallel = YES;
LastUpgradeCheck = 1600;
TargetAttributes = {
183D479E6DE0A841E5AFCFFB = {
DevelopmentTeam = "";
};
8FE1094769F2A06EF7E1D49C = {
DevelopmentTeam = "";
};
};
};
buildConfigurationList = 04D27A61D5C48930CE548C62 /* Build configuration list for PBXProject "PeekMark" */;
developmentRegion = en;
Expand Down Expand Up @@ -365,6 +357,7 @@
CODE_SIGN_ENTITLEMENTS = QuickMarkQL/QuickMarkQL.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = M924X3MR87;
INFOPLIST_FILE = QuickMarkQL/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -472,6 +465,7 @@
CODE_SIGN_ENTITLEMENTS = QuickMarkApp/QuickMarkApp.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = M924X3MR87;
INFOPLIST_FILE = QuickMarkApp/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down
8 changes: 8 additions & 0 deletions QuickMarkApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleName</key>
<string>PeekMark</string>
<key>CFBundleDisplayName</key>
Expand Down
9 changes: 6 additions & 3 deletions QuickMarkApp/Sources/ContentView.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import AppKit
import SwiftUI

struct ContentView: View {
@Environment(\.openSettings) private var openSettings

var body: some View {
VStack(spacing: 20) {
Image(systemName: "doc.text.magnifyingglass")
.font(.system(size: 56))
.foregroundStyle(.secondary)
Image(nsImage: NSApplication.shared.applicationIconImage)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 88, height: 88)
.accessibilityHidden(true)
Text("PeekMark")
.font(.title.bold())
Text("Quick Look preview is ready.\nSelect a Markdown file in Finder, then press Space to preview.")
Expand Down
98 changes: 96 additions & 2 deletions QuickMarkApp/Sources/MarkdownPreviewWindow.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import AppKit
import WebKit
import QuickMarkCore
import UniformTypeIdentifiers

/// A floating split-view window:
/// Left → editable NSTextView with raw Markdown source
Expand Down Expand Up @@ -213,6 +214,7 @@ final class SplitPreviewViewController: NSSplitViewController, NSToolbarDelegate

func load(markdown: String, url: URL) {
editorVC.setText(markdown)
previewVC.sourceURL = url
previewVC.baseURL = url.deletingLastPathComponent()
previewVC.render(markdown: markdown, baseURL: url.deletingLastPathComponent())
editorVC.setCurrentURL(url)
Expand All @@ -221,6 +223,7 @@ final class SplitPreviewViewController: NSSplitViewController, NSToolbarDelegate
func loadNew() {
editorVC.setText("")
editorVC.setCurrentURL(nil)
previewVC.sourceURL = nil
previewVC.baseURL = nil
previewVC.render(markdown: "")
viewMode = .both
Expand All @@ -247,6 +250,65 @@ final class SplitPreviewViewController: NSSplitViewController, NSToolbarDelegate
flashTitle("✓ HTML Copied")
}

func exportDocument(using exporter: any DocumentExporting) {
let panel = NSSavePanel()
panel.title = exporter.format.displayName
panel.nameFieldStringValue = "\(window?.title ?? "Untitled").\(exporter.format.filenameExtension)"
if let contentType = UTType(filenameExtension: exporter.format.filenameExtension) {
panel.allowedContentTypes = [contentType]
}

let completion: (NSApplication.ModalResponse) -> Void = { [weak self] response in
guard response == .OK, let destinationURL = panel.url, let self else { return }
let sourceURL = editorVC.documentURL
let purpose: RenderPurpose
switch exporter.format.filenameExtension.lowercased() {
case "pdf": purpose = .pdfExport
case "docx": purpose = .docxExport
default: purpose = .htmlExport
}
let context = RenderContext(
sourceURL: sourceURL,
title: window?.title ?? "PeekMark",
purpose: purpose
)
let provider = QuickMarkExtensionRegistry.customizationProviders.first
let markdown = editorVC.markdownText

Task { @MainActor [weak self] in
guard let self else { return }
do {
let customization = try await provider?.customization(for: context) ?? .none
let html = MarkdownRenderer.render(
markdown: markdown,
title: context.title,
customization: customization
)
try await exporter.export(ExportRequest(
html: html,
context: context,
destinationURL: destinationURL
))
flashTitle("✓ Exported")
NSWorkspace.shared.activateFileViewerSelecting([destinationURL])
} catch {
let alert = NSAlert(error: error)
alert.messageText = "Unable to Export Document"
if let hostWindow = window ?? NSApp.keyWindow {
alert.beginSheetModal(for: hostWindow) { _ in }
} else {
alert.runModal()
}
}
}
}
if let hostWindow = window ?? NSApp.keyWindow {
panel.beginSheetModal(for: hostWindow, completionHandler: completion)
} else {
panel.begin(completionHandler: completion)
}
}

@objc func findInSource(_ sender: Any?) {
editorVC.showFindPanel()
}
Expand Down Expand Up @@ -388,6 +450,7 @@ final class SplitPreviewViewController: NSSplitViewController, NSToolbarDelegate
final class EditorViewController: NSViewController {
var onTextChange: ((String) -> Void)?
var markdownText: String { textView.string }
var documentURL: URL? { currentURL }

private var currentURL: URL?
private var securityScopedURL: URL?
Expand Down Expand Up @@ -513,7 +576,9 @@ extension EditorViewController: NSTextViewDelegate {

final class PreviewWebViewController: NSViewController, WKNavigationDelegate {
var baseURL: URL?
var sourceURL: URL?
private var webView: WKWebView!
private var renderTask: Task<Void, Never>?

override func loadView() {
let config = WKWebViewConfiguration()
Expand All @@ -525,8 +590,37 @@ final class PreviewWebViewController: NSViewController, WKNavigationDelegate {

func render(markdown: String, baseURL: URL? = nil) {
let resolvedBase = baseURL ?? self.baseURL
let html = MarkdownRenderer.render(markdown: markdown, title: "Preview")
webView.loadHTMLString(html, baseURL: resolvedBase)
let context = RenderContext(sourceURL: sourceURL, title: "Preview", purpose: .appPreview)
let provider = QuickMarkExtensionRegistry.customizationProviders.first

renderTask?.cancel()
renderTask = Task { @MainActor [weak self] in
do {
try await Task.sleep(for: .milliseconds(150))
} catch {
return
}
guard !Task.isCancelled else { return }

let customization: RenderCustomization
if let provider {
do {
customization = try await provider.customization(for: context)
} catch {
customization = .none
}
} else {
customization = .none
}
guard !Task.isCancelled, let self else { return }

let html = MarkdownRenderer.render(
markdown: markdown,
title: context.title,
customization: customization
)
webView.loadHTMLString(html, baseURL: resolvedBase)
}
}

func webView(_ webView: WKWebView,
Expand Down
43 changes: 37 additions & 6 deletions QuickMarkApp/Sources/QuickMarkApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import SwiftUI
import Foundation
import AppKit
import Carbon
import QuickMarkCore

@main
struct QuickMarkApp: App {
Expand All @@ -10,6 +11,7 @@ struct QuickMarkApp: App {

init() {
QuickMarkSettings.registerDefaults()
QuickMarkExtensionLoader.loadConfiguredModule()
ScratchpadHotKeyManager.shared.start()
}

Expand All @@ -20,15 +22,14 @@ struct QuickMarkApp: App {
}
.windowStyle(.titleBar)
.windowToolbarStyle(.unified)
.windowResizability(.contentSize)
.defaultSize(width: 480, height: 300)
.commands {
QuickMarkFileCommands()
CommandGroup(replacing: .saveItem) {
Button("Save") {
activeSplitPreviewViewController()?.saveCurrentFile(nil)
}
.keyboardShortcut("s")
}
#if OFFICIAL_EXTENSIONS
OfficialOptionalCommands()
#endif
QuickMarkSaveCommands()
CommandGroup(after: .pasteboard) {
Button("Copy Rendered HTML") {
activeSplitPreviewViewController()?.copyHTML(nil)
Expand Down Expand Up @@ -56,6 +57,36 @@ struct QuickMarkApp: App {
}
}

struct QuickMarkSaveCommands: Commands {
@ObservedObject private var runtimeState = QuickMarkExtensionRegistry.runtimeState

private var exporters: [any DocumentExporting] {
_ = runtimeState.revision
return QuickMarkExtensionRegistry.exporters
}

var body: some Commands {
CommandGroup(replacing: .saveItem) {
Button("Save") {
activeSplitPreviewViewController()?.saveCurrentFile(nil)
}
.keyboardShortcut("s")

if !exporters.isEmpty {
Divider()
Menu("Export") {
ForEach(exporters.indices, id: \.self) { index in
let exporter = exporters[index]
Button("Export as \(exporter.format.displayName)…") {
activeSplitPreviewViewController()?.exportDocument(using: exporter)
}
}
}
}
}
}
}

final class QuickMarkAppDelegate: NSObject, NSApplicationDelegate {
func applicationShouldOpenUntitledFile(_ sender: NSApplication) -> Bool {
false
Expand Down
16 changes: 11 additions & 5 deletions QuickMarkApp/Sources/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ private struct GeneralSettingsView: View {
.foregroundStyle(.secondary)
.font(.subheadline)
}
Section("Pro Features") {
Text("Custom themes, workspace search, and PDF export are planned for PeekMark Pro.")
#if OFFICIAL_EXTENSIONS
OfficialOptionalFeaturesSettingsView()
#else
Section("Optional Features") {
Text("Custom themes, workspace search, and additional export formats are available in official editions.")
.foregroundStyle(.secondary)
.font(.subheadline)
Button("Learn More…") {
NSWorkspace.shared.open(URL(string: "https://peekmark.app")!)
}
}
#endif
}
.formStyle(.grouped)
}
Expand Down Expand Up @@ -92,9 +96,11 @@ private struct PreviewSettingsView: View {
private struct AboutView: View {
var body: some View {
VStack(spacing: 12) {
Image(systemName: "doc.text.magnifyingglass")
.font(.system(size: 48))
.foregroundStyle(.secondary)
Image(nsImage: NSApplication.shared.applicationIconImage)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 72, height: 72)
.accessibilityHidden(true)
Text("PeekMark")
.font(.title2.bold())
Text("Version 0.1.0 (Community)")
Expand Down
Loading