Skip to content

Commit

Permalink
Experimental support for defining the size of the Quick Look window.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbarex committed Dec 27, 2021
1 parent 6fab894 commit e70882f
Show file tree
Hide file tree
Showing 12 changed files with 234 additions and 69 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog


### 1.0.9 (34)
New features:
- Experimental support for defining the size of the Quick Look window.
- Magic `file` updated to release 5.41.
Bugfix:
- Fixed cross compile compilation of `file` library.

### 1.0.8 (33)
Bugfix:
- Fixed bug for undefined source code theme.
Expand All @@ -10,7 +17,6 @@ Bugfix:
New features:
- Support for render the markdown source code instead of the formatted output.


### 1.0.6 (31)
New features:
- Application menu item to install/reveal the CLI tool on `/usr/local/bin` folder.
Expand Down
1 change: 1 addition & 0 deletions MakefileRe2
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ endif
@echo ""

all: check_arch ${BUILD_DIR}/libre2.dylib
install: check_arch ${BUILD_DIR}/libre2.dylib
4 changes: 3 additions & 1 deletion QLExtension/PreviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class PreviewViewController: NSViewController, QLPreviewingController {

let settings = Settings.shared

self.preferredContentSize = settings.qlWindowSize

let previewRect: CGRect
if #available(macOS 11, *) {
previewRect = self.view.bounds
Expand Down Expand Up @@ -201,7 +203,7 @@ class PreviewViewController: NSViewController, QLPreviewingController {
do {
Settings.shared.initFromDefaults()
let html = try renderMD(url: request.fileURL)
let replay = QLPreviewReply(dataOfContentType: .html, contentSize: .zero) { _ in
let replay = QLPreviewReply(dataOfContentType: .html, contentSize: Settings.shared.qlWindowSize) { _ in
return html.data(using: .utf8)!
}

Expand Down
16 changes: 8 additions & 8 deletions QLMarkdown.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@
CODE_SIGN_ENTITLEMENTS = QLExtension/QLExtension.entitlements;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 33;
CURRENT_PROJECT_VERSION = 34;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = NO;
HEADER_SEARCH_PATHS = (
Expand All @@ -1447,7 +1447,7 @@
"$(PROJECT_DIR)/re2",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.0.8;
MARKETING_VERSION = 1.0.9;
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.QLMarkdown.QLExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1464,7 +1464,7 @@
CODE_SIGN_ENTITLEMENTS = QLExtension/QLExtension.entitlements;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 33;
CURRENT_PROJECT_VERSION = 34;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = NO;
HEADER_SEARCH_PATHS = (
Expand All @@ -1485,7 +1485,7 @@
"$(PROJECT_DIR)/re2",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.0.8;
MARKETING_VERSION = 1.0.9;
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.QLMarkdown.QLExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -1671,7 +1671,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 33;
CURRENT_PROJECT_VERSION = 34;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -1697,7 +1697,7 @@
"$(PROJECT_DIR)/re2",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.0.8;
MARKETING_VERSION = 1.0.9;
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.QLMarkdown;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1718,7 +1718,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 33;
CURRENT_PROJECT_VERSION = 34;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -1744,7 +1744,7 @@
"$(PROJECT_DIR)/re2",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.0.8;
MARKETING_VERSION = 1.0.9;
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.QLMarkdown;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
195 changes: 141 additions & 54 deletions QLMarkdown/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions QLMarkdown/Settings+ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ extension Settings {
defaultsDomain["inline-link"] = openInlineLink
defaultsDomain["render-as-code"] = self.renderAsCode

defaultsDomain["ql-window-width"] = self.qlWindowWidth
defaultsDomain["ql-window-height"] = self.qlWindowHeight

let file: String
if let url = customCSS {
if let folder = Settings.stylesFolder?.path, url.path.hasPrefix(folder) {
Expand Down
17 changes: 17 additions & 0 deletions QLMarkdown/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ class Settings {
@objc var openInlineLink: Bool = false

@objc var renderAsCode: Bool = false
var qlWindowWidth: Int? = nil
var qlWindowHeight: Int? = nil
var qlWindowSize: CGSize {
if let w = qlWindowWidth, w > 0, let h = qlWindowHeight, h > 0 {
return CGSize(width: w, height: h)
} else {
return .zero
}
}
@objc var debug: Bool = false


Expand Down Expand Up @@ -254,6 +263,12 @@ class Settings {
if let opt = defaultsDomain["render-as-code"] as? Bool {
renderAsCode = opt
}
if let opt = defaultsDomain["ql-window-width"] as? Int, opt > 0 {
qlWindowWidth = opt
}
if let opt = defaultsDomain["ql-window-height"] as? Int, opt > 0 {
qlWindowHeight = opt
}

sanitizeEmojiOption()
}
Expand Down Expand Up @@ -312,6 +327,8 @@ class Settings {

self.debug = s.debug
self.renderAsCode = s.renderAsCode
self.qlWindowWidth = s.qlWindowWidth
self.qlWindowHeight = s.qlWindowHeight

DistributedNotificationCenter.default().post(name: .QLMarkdownSettingsUpdated, object: nil)
}
Expand Down
29 changes: 27 additions & 2 deletions QLMarkdown/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,22 @@ class ViewController: NSViewController {
isDirty = true
}
}

@objc dynamic var qlWindowSizeCustomized: Bool = false {
didSet {
isDirty = true
}
}
@objc dynamic var qlWindowWidth: Int = Settings.factorySettings.qlWindowWidth ?? 1000 {
didSet {
isDirty = true
}
}
@objc dynamic var qlWindowHeight: Int = Settings.factorySettings.qlWindowHeight ?? 800 {
didSet {
isDirty = true
}
}

@objc dynamic var customCSSOverride: Bool = Settings.factorySettings.customCSSOverride {
didSet {
Expand Down Expand Up @@ -413,6 +429,9 @@ class ViewController: NSViewController {

@IBOutlet weak var appearanceButton: NSButton!

@IBOutlet weak var gridView: NSGridView!
@IBOutlet weak var qlWindowSizeButton: NSButton!

private let log = {
return OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "quicklook.qlmarkdown-host")
}()
Expand Down Expand Up @@ -663,7 +682,7 @@ document.addEventListener('scroll', function(e) {
</script>
"""

let html = settings.getCompleteHTML(title: ".md", body: body, header: header, footer: "", basedir: Bundle.main.resourceURL ?? Bundle.main.bundleURL.deletingLastPathComponent(), forAppearance: appearance)
let html = settings.getCompleteHTML(title: ".md", body: body, header: header, footer: "", basedir: self.markdown_file?.deletingLastPathComponent() ?? Bundle.main.resourceURL ?? Bundle.main.bundleURL.deletingLastPathComponent(), forAppearance: appearance)
webView.loadHTMLString(html, baseURL: markdown_file?.deletingLastPathComponent())
}

Expand Down Expand Up @@ -983,6 +1002,10 @@ document.addEventListener('scroll', function(e) {
self.debugMode = settings.debug
self.renderAsCode = settings.renderAsCode

self.qlWindowSizeCustomized = settings.qlWindowWidth ?? 0 > 0 && settings.qlWindowHeight ?? 0 > 0
self.qlWindowWidth = settings.qlWindowWidth ?? 1000
self.qlWindowHeight = settings.qlWindowHeight ?? 800

self.tableExtension = settings.tableExtension
self.autoLinkExtension = settings.autoLinkExtension
self.tagFilterExtension = settings.tagFilterExtension
Expand Down Expand Up @@ -1068,6 +1091,8 @@ document.addEventListener('scroll', function(e) {

settings.debug = self.debugMode
settings.renderAsCode = self.renderAsCode
settings.qlWindowWidth = self.qlWindowSizeCustomized ? self.qlWindowWidth : nil
settings.qlWindowHeight = self.qlWindowSizeCustomized ? self.qlWindowHeight : nil

settings.tableExtension = self.tableExtension
settings.autoLinkExtension = self.autoLinkExtension
Expand Down Expand Up @@ -1290,7 +1315,7 @@ class DropableTextView: NSTextView {
func endDrag(_ sender: NSDraggingInfo) {
if let fileUrl = sender.draggingPasteboard.pasteboardItems?.first?.propertyList(forType: .fileURL) as? String, let url = URL(string: fileUrl) {

print(url.path)
// print(url.path)
} else {
print("fail")
}
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

# QLMarkdown

QLMarkdown is a macOS Quick Look extension to preview Markdown files. It can also preview textbundle packages and rmarkdown (`.rmd`) files (_without_ evaluating `r` code).
QLMarkdown is a macOS Quick Look extension to preview Markdown files.

> **Please note that this software is provided "as is", without any warranty of any kind.**
The Quick Look extension can also preview textbundle packages and rmarkdown (`.rmd`) files (_without_ evaluating `r` code).

You can download the last compiled release (as universal binary) from [this link](https://github.com/sbarex/QLMarkdown/releases). The application also has the automatic update function.

- [Screenshots](#screenshots)
Expand Down Expand Up @@ -126,7 +128,9 @@ The options follow those offered by the `cmark-gfm`:

In the advanced options, you can also choose if open external link inside the Quick Look preview window or in the default browser.

With the `Render source code` enabled, the preview shows the highlighted source code instead of the formatted output.
With the `Render source code` enabled _(available on advanced options panel)_, the preview shows the highlighted source code instead of the formatted output.

The `Quick Look size` field _(available on advanced options panel)_ allow you to force a custom size for the content area of the Quick Look window. _Use with caution on macOS before version 12 Monterey_.

### Extensions

Expand Down
Binary file modified assets/img/main_interface_advanced.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/img/preview-screenshot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 21 additions & 1 deletion highlight-wrapper/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,24 @@ build/*
**/.libs/*
**/.deps/*

lua-5.4.2/
lua-5.4.2/

file-5.41/config.h
file-5.41/config.log
file-5.41/config.status
file-5.41/libmagic.pc
file-5.41/libmagic.pc.in
file-5.41/libtool
file-5.41/Makefile
file-5.41/stamp-h1
file-5.41/doc/Makefile
file-5.41/doc/file.1
file-5.41/doc/libmagic.3
file-5.41/doc/magic.4
file-5.41/tests/Makefile
file-5.41/magic/magic.mgc
file-5.41/magic/Makefile
file-5.41/python/Makefile
file-5.41/src/file
file-5.41/src/magic.h
file-5.41/src/Makefile

0 comments on commit e70882f

Please sign in to comment.