Skip to content

Commit 609acf8

Browse files
committed
Bugfix for binary plain file.
1 parent e55130d commit 609acf8

File tree

13 files changed

+117
-79
lines changed

13 files changed

+117
-79
lines changed

Application/HighlightWrapper.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class HighlightWrapper {
131131
theme.isStandalone = false
132132
self.themes.append(theme)
133133
NotificationCenter.default.post(name: NSNotification.Name.CustomThemeAdded, object: theme)
134+
SCSHWrapper.shared.settings?.isDirty = true
134135
}
135136

136137
/// Remove a custom theme.
@@ -182,7 +183,7 @@ class HighlightWrapper {
182183
}
183184
alert.addButton(withTitle: "Yes")
184185
alert.addButton(withTitle: "No").keyEquivalent = "\u{1b}"
185-
alert.alertStyle = .warning
186+
alert.alertStyle = .critical
186187

187188
if let win = window {
188189
alert.beginSheetModal(for: win) { (response) in

Application/SettingsSplitViewController.swift

+7-5
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,13 @@ class SettingsSplitViewController: NSSplitViewController {
220220
alert.runModal()
221221
return
222222
}
223-
let alert = NSAlert()
224-
alert.messageText = "Settings saved."
225-
alert.addButton(withTitle: "Close")
226-
alert.alertStyle = .informational
227-
alert.runModal()
223+
if SCSHWrapper.shared.settings?.isDebug ?? false {
224+
let alert = NSAlert()
225+
alert.messageText = "Settings saved."
226+
alert.addButton(withTitle: "Close")
227+
alert.alertStyle = .informational
228+
alert.runModal()
229+
}
228230
}
229231
}
230232

Application/String+ext.swift

+39-14
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,29 @@ extension String {
6868
/// - font: Font name.
6969
/// - fontSize: Font size.
7070
/// - returns: The formatted data.
71-
func toData(format: Settings.Format, fgColor: String? = nil, bgColor: String? = nil, font: String? = nil, fontSize: CGFloat? = nil) -> Data {
72-
return String.stringToFormattedData(self, format: format, fgColor: fgColor, bgColor: bgColor, font: font, fontSize: fontSize)
71+
func toData(format: Settings.Format, fgColor: String? = nil, bgColor: String? = nil, font: String? = nil, fontSize: CGFloat? = nil, css: String = "") -> Data {
72+
return String.stringToFormattedData(self, format: format, fgColor: fgColor, bgColor: bgColor, font: font, fontSize: fontSize, css: css)
7373
}
74-
func toData(settings: SettingsRendering) -> Data {
74+
func toData(settings: SettingsRendering, cssFile: URL? = nil) -> Data {
7575
let colors = settings.getTheme()
76-
return String.stringToFormattedData(self, format: settings.format, fgColor: colors.foreground, bgColor: colors.background, font: settings.fontName, fontSize: settings.fontSize)
76+
var css = settings.css
77+
if let file = cssFile, let s = try? String(contentsOf: file) {
78+
css = s + css
79+
}
80+
return String.stringToFormattedData(self, format: settings.format, fgColor: colors.foreground, bgColor: colors.background, font: settings.fontName, fontSize: settings.fontSize, css: css)
7781
}
7882

79-
func toHTML(fgColor: String? = nil, bgColor: String? = nil, font: String? = nil, fontSize: CGFloat? = nil) -> String {
80-
let data = self.toData(format: .html, fgColor: fgColor, bgColor: bgColor, font: font, fontSize: fontSize)
83+
func toHTML(fgColor: String? = nil, bgColor: String? = nil, font: String? = nil, fontSize: CGFloat? = nil, css: String = "") -> String {
84+
let data = self.toData(format: .html, fgColor: fgColor, bgColor: bgColor, font: font, fontSize: fontSize, css: css)
8185
return String(data: data, encoding: .utf8)!
8286
}
83-
func toHTML(settings: SettingsRendering) -> String {
87+
func toHTML(settings: SettingsRendering, cssFile: URL? = nil) -> String {
8488
let colors = settings.getTheme()
85-
return toHTML(fgColor: colors.foreground, bgColor: colors.background, font: settings.fontName, fontSize: settings.fontSize)
89+
var css = settings.css
90+
if let file = cssFile, let s = try? String(contentsOf: file) {
91+
css = s + css
92+
}
93+
return toHTML(fgColor: colors.foreground, bgColor: colors.background, font: settings.fontName, fontSize: settings.fontSize, css: css)
8694
}
8795

8896
func toRTF(fgColor: String? = nil, bgColor: String? = nil, font: String? = nil, fontSize: CGFloat? = nil) -> Data {
@@ -103,7 +111,7 @@ extension String {
103111
return NSAttributedString(rtf: data, documentAttributes: nil)
104112
}
105113

106-
static func stringToFormattedData(_ string: String, format: Settings.Format, fgColor: String? = nil, bgColor: String? = nil, font: String? = nil, fontSize: CGFloat? = nil) -> Data {
114+
static func stringToFormattedData(_ string: String, format: Settings.Format, fgColor: String? = nil, bgColor: String? = nil, font: String? = nil, fontSize: CGFloat? = nil, css: String = "") -> Data {
107115
let labelColor: NSColor?
108116
if let s = fgColor, let c = NSColor(fromHexString: s) {
109117
labelColor = c
@@ -126,15 +134,19 @@ extension String {
126134
} else {
127135
font1 = nil
128136
}
129-
return stringToFormattedData(string, format: format, fgColor: labelColor, bgColor: backgroundColor, font: font1)
137+
return stringToFormattedData(string, format: format, fgColor: labelColor, bgColor: backgroundColor, font: font1, css: css)
130138
}
131139

132-
static func stringToFormattedData(_ string: String, settings: SettingsRendering) -> Data {
140+
static func stringToFormattedData(_ string: String, settings: SettingsRendering, cssFile: URL? = nil) -> Data {
133141
let colors = settings.getTheme()
134-
return stringToFormattedData(string, format: settings.format, fgColor: colors.foreground, bgColor: colors.background, font: settings.fontName, fontSize: settings.fontSize)
142+
var css = settings.css
143+
if let file = cssFile, let s = try? String(contentsOf: file) {
144+
css = s + css
145+
}
146+
return stringToFormattedData(string, format: settings.format, fgColor: colors.foreground, bgColor: colors.background, font: settings.fontName, fontSize: settings.fontSize, css: css)
135147
}
136148

137-
static func stringToFormattedData(_ string: String, format: Settings.Format, fgColor: NSColor? = nil, bgColor: NSColor? = nil, font: NSFont? = nil) -> Data {
149+
static func stringToFormattedData(_ string: String, format: Settings.Format, fgColor: NSColor? = nil, bgColor: NSColor? = nil, font: NSFont? = nil, css: String = "") -> Data {
138150
let labelColor: NSColor
139151
if let c = fgColor {
140152
labelColor = c
@@ -176,14 +188,27 @@ body {
176188
color: \(fg_color);
177189
font: \(font1.pointSize)pt \(font1.fontName);
178190
}
191+
\(css)
179192
</style>
180193
</head>
181-
<body>
194+
<body class="hl">
195+
<pre class="hl">
182196
\(string)
197+
</pre>
183198
</body>
184199
</html>
185200
"""
186201
return s.data(using: .utf8)!
187202
}
188203
}
204+
205+
func htmlEntitites() -> String {
206+
return self
207+
.replacingOccurrences(of: "&", with: "&amp;")
208+
.replacingOccurrences(of: "<", with: "&lt;")
209+
.replacingOccurrences(of: ">", with: "&gt;")
210+
.replacingOccurrences(of: "\"", with: "&quot;")
211+
.replacingOccurrences(of: "'", with: "&#039;")
212+
// .replacingOccurrences(of: "\n", with: "<br />")
213+
}
189214
}
Binary file not shown.

Application/ThemeEditorView.swift

+13
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class ThemeEditorView: NSView, SettingsSplitViewElement {
3838
guard oldValue != theme else {
3939
return
4040
}
41+
42+
oldValue?.delegate = nil
43+
theme?.delegate = self
44+
4145
if let theme = self.theme {
4246
scrollView.isHidden = false
4347
horizontalLine1.isHidden = false
@@ -731,3 +735,12 @@ class ThemeCellView: NSTableCellView {
731735
delKeywordAction?(self.tag)
732736
}
733737
}
738+
739+
// MARK: -
740+
extension ThemeEditorView: SCSHThemeDelegate {
741+
func themeDidChangeDirtyStatus(_ theme: SCSHTheme) {
742+
if theme.isDirty {
743+
SCSHWrapper.shared.settings?.isDirty = true
744+
}
745+
}
746+
}

Application/resources/vcs.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ function syntaxUpdate(desc)
149149
end
150150
else
151151
if currentMark == '+' then
152-
return '<span class="hl vcs add title="Line added.">'
152+
return '<span class="hl vcs add" title="Line added.">'
153153
elseif currentMark == 'M' then
154154
return '<span class="hl vcs changed" title="Line changed.">'
155155
elseif currentMark == '-' then
156-
return '<hr class="hl vcs del" title="Line deleted." />' -- '<span class="hl vcs del" ></span>'
156+
return '<hr class="hl vcs del" title="Line deleted." />' -- '<span class="hl vcs del" ></span>'
157157
else
158158
return ''
159159
end

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ Changelog
22
=======
33

44

5+
### 2.1.2 (49)
6+
Bugfix:
7+
- Fixed dirty status do not set when change a theme property.
8+
- Fixed binary dump word wrap and html entities.
9+
- Better strict detection of plain image files.
10+
511
### 2.1.1 (48)
612
New features:
713
- Application menu item to install/reveal the CLI tool on `/usr/local/bin` folder.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ You can set the settings for all supported formats on the _General_ tab.
220220

221221
|Settings|Description|Advanced|
222222
|:---------|:-------------| :----: |
223-
|Render engine|Engine used to render the highlighted code. _Before macOS 12 Monterey_ **the suggested engine is `RTF`.** Choose the `HTML` engine if you want to use a custom CSS to override the color scheme (or you have choose a theme with some extra CSS inside it). Advanced users must choose the `HTML` engine to handle the hover functionality of a Language Server. ||
223+
|Render engine|Engine used to render the highlighted code. _Before macOS 12 Monterey_ **the recommended engine is `RTF`.** Choose the `HTML` engine if you want to use a custom CSS to override the color scheme (or you have choose a theme with some extra CSS inside it). Advanced users must choose the `HTML` engine to handle the hover functionality of a Language Server. ||
224224
|Color scheme|Chose the color scheme for light and dark appearance.||
225225
|Font|You can chose a preferred font or use the standard monospaced font.||
226226
|Word wrap|Allow to handle word wrap for long lines. _Hard wrap_ break the line after a fixed length (_can cause some highlight glitch_). _Soft wraps_ allow to break the line at the preview windows width. When word wraps is disabled, you can only enable it for minified files that have only one line. One line file detection is done on the source file and not on the preprocessor output. **Starting from macOS 12 Monterey the soft wrap is always enabled when using the `RTF` engine.** ||

SourceCodeSyntaxHighlight.xcodeproj/project.pbxproj

+16-16
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,7 @@
19121912
CODE_SIGN_IDENTITY = "-";
19131913
CODE_SIGN_STYLE = Manual;
19141914
COMBINE_HIDPI_IMAGES = YES;
1915-
CURRENT_PROJECT_VERSION = 48;
1915+
CURRENT_PROJECT_VERSION = 49;
19161916
DEVELOPMENT_TEAM = "";
19171917
ENABLE_HARDENED_RUNTIME = YES;
19181918
FRAMEWORK_SEARCH_PATHS = (
@@ -1930,7 +1930,7 @@
19301930
"$(inherited)",
19311931
"\"$(BUILT_PRODUCTS_DIR)/highlight\"",
19321932
);
1933-
MARKETING_VERSION = 2.1.1;
1933+
MARKETING_VERSION = 2.1.2;
19341934
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.SourceCodeSyntaxHighlight;
19351935
PRODUCT_NAME = "$(TARGET_NAME)";
19361936
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -1948,7 +1948,7 @@
19481948
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
19491949
CODE_SIGN_STYLE = Manual;
19501950
COMBINE_HIDPI_IMAGES = YES;
1951-
CURRENT_PROJECT_VERSION = 48;
1951+
CURRENT_PROJECT_VERSION = 49;
19521952
DEVELOPMENT_TEAM = "";
19531953
ENABLE_HARDENED_RUNTIME = YES;
19541954
FRAMEWORK_SEARCH_PATHS = (
@@ -1966,7 +1966,7 @@
19661966
"$(inherited)",
19671967
"\"$(BUILT_PRODUCTS_DIR)/highlight\"",
19681968
);
1969-
MARKETING_VERSION = 2.1.1;
1969+
MARKETING_VERSION = 2.1.2;
19701970
OTHER_CODE_SIGN_FLAGS = "--timestamp";
19711971
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.SourceCodeSyntaxHighlight;
19721972
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1982,7 +1982,7 @@
19821982
CODE_SIGN_ENTITLEMENTS = QLExtension/QLExtension.entitlements;
19831983
CODE_SIGN_IDENTITY = "-";
19841984
CODE_SIGN_STYLE = Manual;
1985-
CURRENT_PROJECT_VERSION = 48;
1985+
CURRENT_PROJECT_VERSION = 49;
19861986
DEVELOPMENT_TEAM = "";
19871987
ENABLE_HARDENED_RUNTIME = YES;
19881988
FRAMEWORK_SEARCH_PATHS = (
@@ -1995,7 +1995,7 @@
19951995
"@executable_path/../Frameworks",
19961996
"@executable_path/../../../../Frameworks",
19971997
);
1998-
MARKETING_VERSION = 2.1.1;
1998+
MARKETING_VERSION = 2.1.2;
19991999
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.SourceCodeSyntaxHighlight.QuicklookExtension;
20002000
PRODUCT_NAME = "$(TARGET_NAME)";
20012001
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -2011,7 +2011,7 @@
20112011
CODE_SIGN_IDENTITY = "-";
20122012
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
20132013
CODE_SIGN_STYLE = Manual;
2014-
CURRENT_PROJECT_VERSION = 48;
2014+
CURRENT_PROJECT_VERSION = 49;
20152015
DEVELOPMENT_TEAM = "";
20162016
ENABLE_HARDENED_RUNTIME = YES;
20172017
FRAMEWORK_SEARCH_PATHS = (
@@ -2024,7 +2024,7 @@
20242024
"@executable_path/../Frameworks",
20252025
"@executable_path/../../../../Frameworks",
20262026
);
2027-
MARKETING_VERSION = 2.1.1;
2027+
MARKETING_VERSION = 2.1.2;
20282028
OTHER_CODE_SIGN_FLAGS = "--timestamp";
20292029
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.SourceCodeSyntaxHighlight.QuicklookExtension;
20302030
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -2041,7 +2041,7 @@
20412041
CODE_SIGN_IDENTITY = "-";
20422042
CODE_SIGN_STYLE = Manual;
20432043
COMBINE_HIDPI_IMAGES = YES;
2044-
CURRENT_PROJECT_VERSION = 48;
2044+
CURRENT_PROJECT_VERSION = 49;
20452045
DEVELOPMENT_TEAM = "";
20462046
ENABLE_HARDENED_RUNTIME = YES;
20472047
INFOPLIST_FILE = XPCService/Info.plist;
@@ -2050,7 +2050,7 @@
20502050
"$(LD_RUNPATH_SEARCH_PATHS_$(IS_MACCATALYST)_$(_BOOL_$(SKIP_INSTALL)))",
20512051
);
20522052
LIBRARY_SEARCH_PATHS = "\"$(BUILT_PRODUCTS_DIR)/highlight\"";
2053-
MARKETING_VERSION = 2.1.1;
2053+
MARKETING_VERSION = 2.1.2;
20542054
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.SourceCodeSyntaxHighlight.XPCService;
20552055
PRODUCT_NAME = "$(TARGET_NAME)";
20562056
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -2069,7 +2069,7 @@
20692069
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
20702070
CODE_SIGN_STYLE = Manual;
20712071
COMBINE_HIDPI_IMAGES = YES;
2072-
CURRENT_PROJECT_VERSION = 48;
2072+
CURRENT_PROJECT_VERSION = 49;
20732073
DEVELOPMENT_TEAM = "";
20742074
ENABLE_HARDENED_RUNTIME = YES;
20752075
INFOPLIST_FILE = XPCService/Info.plist;
@@ -2078,7 +2078,7 @@
20782078
"$(LD_RUNPATH_SEARCH_PATHS_$(IS_MACCATALYST)_$(_BOOL_$(SKIP_INSTALL)))",
20792079
);
20802080
LIBRARY_SEARCH_PATHS = "\"$(BUILT_PRODUCTS_DIR)/highlight\"";
2081-
MARKETING_VERSION = 2.1.1;
2081+
MARKETING_VERSION = 2.1.2;
20822082
OTHER_CODE_SIGN_FLAGS = "--timestamp";
20832083
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.SourceCodeSyntaxHighlight.XPCService;
20842084
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -2128,7 +2128,7 @@
21282128
CODE_SIGN_IDENTITY = "-";
21292129
CODE_SIGN_STYLE = Manual;
21302130
COMBINE_HIDPI_IMAGES = YES;
2131-
CURRENT_PROJECT_VERSION = 48;
2131+
CURRENT_PROJECT_VERSION = 49;
21322132
DEVELOPMENT_TEAM = "";
21332133
ENABLE_HARDENED_RUNTIME = YES;
21342134
FRAMEWORK_SEARCH_PATHS = (
@@ -2140,7 +2140,7 @@
21402140
"$(inherited)",
21412141
"@loader_path/../../../../Frameworks",
21422142
);
2143-
MARKETING_VERSION = 2.1.1;
2143+
MARKETING_VERSION = 2.1.2;
21442144
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.SourceCodeSyntaxHighlight.XPCRender;
21452145
PRODUCT_NAME = "$(TARGET_NAME)";
21462146
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -2160,7 +2160,7 @@
21602160
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
21612161
CODE_SIGN_STYLE = Manual;
21622162
COMBINE_HIDPI_IMAGES = YES;
2163-
CURRENT_PROJECT_VERSION = 48;
2163+
CURRENT_PROJECT_VERSION = 49;
21642164
DEVELOPMENT_TEAM = "";
21652165
ENABLE_HARDENED_RUNTIME = YES;
21662166
FRAMEWORK_SEARCH_PATHS = (
@@ -2172,7 +2172,7 @@
21722172
"$(inherited)",
21732173
"@loader_path/../../../../Frameworks",
21742174
);
2175-
MARKETING_VERSION = 2.1.1;
2175+
MARKETING_VERSION = 2.1.2;
21762176
OTHER_CODE_SIGN_FLAGS = "--timestamp";
21772177
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.SourceCodeSyntaxHighlight.XPCRender;
21782178
PRODUCT_NAME = "$(TARGET_NAME)";

SyntaxHighlightRenderXPC/MagicAttributes.swift

+1-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ class MagicAttributes {
4141

4242
/// Return if the parsed file is an image.
4343
lazy var isImage: Bool = {
44-
if self.mimeType.hasPrefix("image/") {
45-
return true
46-
} else {
47-
return checkMime(conformTo: kUTTypeImage)
48-
}
44+
return checkMime(conformTo: kUTTypeImage)
4945
}()
5046
/// Return if the parsed file is an image.
5147
var isPDF: Bool {

0 commit comments

Comments
 (0)