Skip to content

Commit e70882f

Browse files
committed
Experimental support for defining the size of the Quick Look window.
1 parent 6fab894 commit e70882f

12 files changed

+234
-69
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Changelog
22

33

4+
### 1.0.9 (34)
5+
New features:
6+
- Experimental support for defining the size of the Quick Look window.
7+
- Magic `file` updated to release 5.41.
8+
Bugfix:
9+
- Fixed cross compile compilation of `file` library.
10+
411
### 1.0.8 (33)
512
Bugfix:
613
- Fixed bug for undefined source code theme.
@@ -10,7 +17,6 @@ Bugfix:
1017
New features:
1118
- Support for render the markdown source code instead of the formatted output.
1219

13-
1420
### 1.0.6 (31)
1521
New features:
1622
- Application menu item to install/reveal the CLI tool on `/usr/local/bin` folder.

MakefileRe2

+1
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,4 @@ endif
9393
@echo ""
9494

9595
all: check_arch ${BUILD_DIR}/libre2.dylib
96+
install: check_arch ${BUILD_DIR}/libre2.dylib

QLExtension/PreviewViewController.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class PreviewViewController: NSViewController, QLPreviewingController {
8080

8181
let settings = Settings.shared
8282

83+
self.preferredContentSize = settings.qlWindowSize
84+
8385
let previewRect: CGRect
8486
if #available(macOS 11, *) {
8587
previewRect = self.view.bounds
@@ -201,7 +203,7 @@ class PreviewViewController: NSViewController, QLPreviewingController {
201203
do {
202204
Settings.shared.initFromDefaults()
203205
let html = try renderMD(url: request.fileURL)
204-
let replay = QLPreviewReply(dataOfContentType: .html, contentSize: .zero) { _ in
206+
let replay = QLPreviewReply(dataOfContentType: .html, contentSize: Settings.shared.qlWindowSize) { _ in
205207
return html.data(using: .utf8)!
206208
}
207209

QLMarkdown.xcodeproj/project.pbxproj

+8-8
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@
14261426
CODE_SIGN_ENTITLEMENTS = QLExtension/QLExtension.entitlements;
14271427
CODE_SIGN_IDENTITY = "-";
14281428
CODE_SIGN_STYLE = Manual;
1429-
CURRENT_PROJECT_VERSION = 33;
1429+
CURRENT_PROJECT_VERSION = 34;
14301430
DEVELOPMENT_TEAM = "";
14311431
ENABLE_HARDENED_RUNTIME = NO;
14321432
HEADER_SEARCH_PATHS = (
@@ -1447,7 +1447,7 @@
14471447
"$(PROJECT_DIR)/re2",
14481448
);
14491449
MACOSX_DEPLOYMENT_TARGET = 10.15;
1450-
MARKETING_VERSION = 1.0.8;
1450+
MARKETING_VERSION = 1.0.9;
14511451
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.QLMarkdown.QLExtension;
14521452
PRODUCT_NAME = "$(TARGET_NAME)";
14531453
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -1464,7 +1464,7 @@
14641464
CODE_SIGN_ENTITLEMENTS = QLExtension/QLExtension.entitlements;
14651465
CODE_SIGN_IDENTITY = "-";
14661466
CODE_SIGN_STYLE = Manual;
1467-
CURRENT_PROJECT_VERSION = 33;
1467+
CURRENT_PROJECT_VERSION = 34;
14681468
DEVELOPMENT_TEAM = "";
14691469
ENABLE_HARDENED_RUNTIME = NO;
14701470
HEADER_SEARCH_PATHS = (
@@ -1485,7 +1485,7 @@
14851485
"$(PROJECT_DIR)/re2",
14861486
);
14871487
MACOSX_DEPLOYMENT_TARGET = 10.15;
1488-
MARKETING_VERSION = 1.0.8;
1488+
MARKETING_VERSION = 1.0.9;
14891489
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.QLMarkdown.QLExtension;
14901490
PRODUCT_NAME = "$(TARGET_NAME)";
14911491
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -1671,7 +1671,7 @@
16711671
CODE_SIGN_IDENTITY = "-";
16721672
CODE_SIGN_STYLE = Manual;
16731673
COMBINE_HIDPI_IMAGES = YES;
1674-
CURRENT_PROJECT_VERSION = 33;
1674+
CURRENT_PROJECT_VERSION = 34;
16751675
DEVELOPMENT_TEAM = "";
16761676
ENABLE_HARDENED_RUNTIME = NO;
16771677
FRAMEWORK_SEARCH_PATHS = (
@@ -1697,7 +1697,7 @@
16971697
"$(PROJECT_DIR)/re2",
16981698
);
16991699
MACOSX_DEPLOYMENT_TARGET = 10.15;
1700-
MARKETING_VERSION = 1.0.8;
1700+
MARKETING_VERSION = 1.0.9;
17011701
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.QLMarkdown;
17021702
PRODUCT_NAME = "$(TARGET_NAME)";
17031703
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -1718,7 +1718,7 @@
17181718
CODE_SIGN_IDENTITY = "-";
17191719
CODE_SIGN_STYLE = Manual;
17201720
COMBINE_HIDPI_IMAGES = YES;
1721-
CURRENT_PROJECT_VERSION = 33;
1721+
CURRENT_PROJECT_VERSION = 34;
17221722
DEVELOPMENT_TEAM = "";
17231723
ENABLE_HARDENED_RUNTIME = NO;
17241724
FRAMEWORK_SEARCH_PATHS = (
@@ -1744,7 +1744,7 @@
17441744
"$(PROJECT_DIR)/re2",
17451745
);
17461746
MACOSX_DEPLOYMENT_TARGET = 10.15;
1747-
MARKETING_VERSION = 1.0.8;
1747+
MARKETING_VERSION = 1.0.9;
17481748
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.QLMarkdown;
17491749
PRODUCT_NAME = "$(TARGET_NAME)";
17501750
PROVISIONING_PROFILE_SPECIFIER = "";

QLMarkdown/Base.lproj/Main.storyboard

+141-54
Large diffs are not rendered by default.

QLMarkdown/Settings+ext.swift

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ extension Settings {
5858
defaultsDomain["inline-link"] = openInlineLink
5959
defaultsDomain["render-as-code"] = self.renderAsCode
6060

61+
defaultsDomain["ql-window-width"] = self.qlWindowWidth
62+
defaultsDomain["ql-window-height"] = self.qlWindowHeight
63+
6164
let file: String
6265
if let url = customCSS {
6366
if let folder = Settings.stylesFolder?.path, url.path.hasPrefix(folder) {

QLMarkdown/Settings.swift

+17
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ class Settings {
7979
@objc var openInlineLink: Bool = false
8080

8181
@objc var renderAsCode: Bool = false
82+
var qlWindowWidth: Int? = nil
83+
var qlWindowHeight: Int? = nil
84+
var qlWindowSize: CGSize {
85+
if let w = qlWindowWidth, w > 0, let h = qlWindowHeight, h > 0 {
86+
return CGSize(width: w, height: h)
87+
} else {
88+
return .zero
89+
}
90+
}
8291
@objc var debug: Bool = false
8392

8493

@@ -254,6 +263,12 @@ class Settings {
254263
if let opt = defaultsDomain["render-as-code"] as? Bool {
255264
renderAsCode = opt
256265
}
266+
if let opt = defaultsDomain["ql-window-width"] as? Int, opt > 0 {
267+
qlWindowWidth = opt
268+
}
269+
if let opt = defaultsDomain["ql-window-height"] as? Int, opt > 0 {
270+
qlWindowHeight = opt
271+
}
257272

258273
sanitizeEmojiOption()
259274
}
@@ -312,6 +327,8 @@ class Settings {
312327

313328
self.debug = s.debug
314329
self.renderAsCode = s.renderAsCode
330+
self.qlWindowWidth = s.qlWindowWidth
331+
self.qlWindowHeight = s.qlWindowHeight
315332

316333
DistributedNotificationCenter.default().post(name: .QLMarkdownSettingsUpdated, object: nil)
317334
}

QLMarkdown/ViewController.swift

+27-2
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,22 @@ class ViewController: NSViewController {
223223
isDirty = true
224224
}
225225
}
226+
227+
@objc dynamic var qlWindowSizeCustomized: Bool = false {
228+
didSet {
229+
isDirty = true
230+
}
231+
}
232+
@objc dynamic var qlWindowWidth: Int = Settings.factorySettings.qlWindowWidth ?? 1000 {
233+
didSet {
234+
isDirty = true
235+
}
236+
}
237+
@objc dynamic var qlWindowHeight: Int = Settings.factorySettings.qlWindowHeight ?? 800 {
238+
didSet {
239+
isDirty = true
240+
}
241+
}
226242

227243
@objc dynamic var customCSSOverride: Bool = Settings.factorySettings.customCSSOverride {
228244
didSet {
@@ -413,6 +429,9 @@ class ViewController: NSViewController {
413429

414430
@IBOutlet weak var appearanceButton: NSButton!
415431

432+
@IBOutlet weak var gridView: NSGridView!
433+
@IBOutlet weak var qlWindowSizeButton: NSButton!
434+
416435
private let log = {
417436
return OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "quicklook.qlmarkdown-host")
418437
}()
@@ -663,7 +682,7 @@ document.addEventListener('scroll', function(e) {
663682
</script>
664683
"""
665684

666-
let html = settings.getCompleteHTML(title: ".md", body: body, header: header, footer: "", basedir: Bundle.main.resourceURL ?? Bundle.main.bundleURL.deletingLastPathComponent(), forAppearance: appearance)
685+
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)
667686
webView.loadHTMLString(html, baseURL: markdown_file?.deletingLastPathComponent())
668687
}
669688

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

1005+
self.qlWindowSizeCustomized = settings.qlWindowWidth ?? 0 > 0 && settings.qlWindowHeight ?? 0 > 0
1006+
self.qlWindowWidth = settings.qlWindowWidth ?? 1000
1007+
self.qlWindowHeight = settings.qlWindowHeight ?? 800
1008+
9861009
self.tableExtension = settings.tableExtension
9871010
self.autoLinkExtension = settings.autoLinkExtension
9881011
self.tagFilterExtension = settings.tagFilterExtension
@@ -1068,6 +1091,8 @@ document.addEventListener('scroll', function(e) {
10681091

10691092
settings.debug = self.debugMode
10701093
settings.renderAsCode = self.renderAsCode
1094+
settings.qlWindowWidth = self.qlWindowSizeCustomized ? self.qlWindowWidth : nil
1095+
settings.qlWindowHeight = self.qlWindowSizeCustomized ? self.qlWindowHeight : nil
10711096

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

1293-
print(url.path)
1318+
// print(url.path)
12941319
} else {
12951320
print("fail")
12961321
}

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
# QLMarkdown
66

7-
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).
7+
QLMarkdown is a macOS Quick Look extension to preview Markdown files.
88

99
> **Please note that this software is provided "as is", without any warranty of any kind.**
1010
11+
The Quick Look extension can also preview textbundle packages and rmarkdown (`.rmd`) files (_without_ evaluating `r` code).
12+
1113
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.
1214

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

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

129-
With the `Render source code` enabled, the preview shows the highlighted source code instead of the formatted output.
131+
With the `Render source code` enabled _(available on advanced options panel)_, the preview shows the highlighted source code instead of the formatted output.
132+
133+
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_.
130134

131135
### Extensions
132136

-17.7 KB
Loading

assets/img/preview-screenshot.png

22.4 KB
Loading

highlight-wrapper/.gitignore

+21-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,24 @@ build/*
77
**/.libs/*
88
**/.deps/*
99

10-
lua-5.4.2/
10+
lua-5.4.2/
11+
12+
file-5.41/config.h
13+
file-5.41/config.log
14+
file-5.41/config.status
15+
file-5.41/libmagic.pc
16+
file-5.41/libmagic.pc.in
17+
file-5.41/libtool
18+
file-5.41/Makefile
19+
file-5.41/stamp-h1
20+
file-5.41/doc/Makefile
21+
file-5.41/doc/file.1
22+
file-5.41/doc/libmagic.3
23+
file-5.41/doc/magic.4
24+
file-5.41/tests/Makefile
25+
file-5.41/magic/magic.mgc
26+
file-5.41/magic/Makefile
27+
file-5.41/python/Makefile
28+
file-5.41/src/file
29+
file-5.41/src/magic.h
30+
file-5.41/src/Makefile

0 commit comments

Comments
 (0)