Swiftpack.co - Package - sbarex/SourceCodeSyntaxHighlight

Quicklook extension for source files

This application offers a quicklook extension for MacOS 10.15 Catalina for previewing source files. Inside it uses Highlight to render source code with syntax highlighting. The application is distributed with a version of the highlight. If you want you can use a different version customizing the preferences.

MacOS 10.15.0 Catalina has deprecated the qlgenerator APIs. Moreover a .qlgenerator package inside Library/QuickLook must be notarized on 10.15.0 to works. In version 10.15.1 it seems that notarization is no longer required.

This project consists of these components:

  • a standalone app that can view source files and provide the interface for the preferences;
  • a quicklook system extension to preview the source files;
  • an XPC service that generate the preview of source file and pass the formatted data to the app or the quicklook extension.

MacOS 10.15 Catalina require sandboxed extension that prevent the execution of external processes (like shell script). To work around this problem, it is possible to use an XPC service that may have different security policies than the application / extension that invokes it. In this case the XPC service is not sandboxed.

The XPC service is executed automatically when requested by the application or the quicklook extension. After closing the quicklook preview the process is automatically closed after some seconds releasing the resources.

The app and quicklook extension can preview files showing the formatted code as html, inside a WKWebView, or as rtf inside a NSTextView.

To use the quicklook preview you must launch the application at least once. In this way the quicklook extension will be discovered by the system. After the first execution, the quicklook extension will be available among those present in the System preferences/Extensions.

System preferences/Extensions

This extension don't provide a thumbnail service for the Finder icon.

SyntaxHighlight is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY.

File format management

The quicklook extension uses the Uniform Type Identifier (UTI) to handle the supported formats (and not simply the file name extension). Inside the definition on an UTI there are the list of extensions and mime type associated with it.

Some file types are directly associated to an UTI by the system. Other formats are registered by the owner application. In this way some extensions can be associated to multiple UTIs based on the applications currently installed.

For this reason, this application supports many UTIs even if they are apparently redundant.

Apparently the operating system does not allow to manage some file formats including (but not limited to) .xml, .plist, .html, .ts, .dart.

It's likely that I didn't associate all the possible extensions managed by highlight.

With the inquiry window you can see if a specific file type is handled by the quicklook extension and also if it is recognized by highlight.

Inquiry window

On Terminal you can see the UTI of a file with this command:

$ mdls -name kMDItemContentType -name kMDItemContentTypeTree filename.ext

If you found an unhandled format please send me the output of above command. Only the formats supported by highlight can be managed by this application.

To view the info about highlight with the supported file formats and extensions go to the menu Syntax Highlight/About highlight…, or in the Preferences window click the i info button near the highlight popup button.

IAbout highlight info panel.

Application preferences

In the standalone app, with the preferences window you can customize the preview settings used by the plugin extension.

Preferences window

The preferences windows has three zones:

  • on the left side the list of the supported UTI file format;
  • on the center the panel to edit the settings;
  • on the right side the preview of current settings.

You can set the settings for all file selecting the Global item on the left list or customize for a specific UTI format. When you customize the settings of a specific format the global preferences are inherited and you can override only the requested options.

In the list of supported file type the grayout items are those currently managed by others UTI. Clicking on the exclamation mark icon you will show which UTI is used for a given file extension.

File type settings window

The settings are stored in ~/Library/Preferences/org.sbarex.SourceCodeSyntaxHighlight.plist. Custom themes and styles are saved in ~/Library/Application Support/Syntax Highlight.

General settings

Global settings window

Selecting the Global item on the left list you can set the general settings of the engine:

  • Highlight: path of the highlight utils. You can choose the embedded version or select a different version (compiled by hand or installed with homebrew for example).
  • Output mode: set the rendering output. Can be html that use the WebKit or rtf that use a NSTextView.
  • Data limit: maximum amount of data to format, data beyond the limit is omitted. Specify 0 to not limit.
  • Debug: enable the generation of the colorize.log and colorize.html|rtf on your desktop for debug purpose.

Appearance settings

Appearance settings window

This section allow to customize the appearance of the rendered source files:

  • Themes: You can choose a theme for light and dark style of the MacOS.
  • Custom style: for html output mode you can set a custom css style to override the theme settings.
  • Font: font family and size to use in the output. Depending on the theme chosen, italic and bold style may be applied to certain elements.
  • Word wrap: handle the style of the work wrap.
  • Line number: you can set the visibility of the line numbers.
  • Tabs: set if the tabs must be converted to space. Setting to zero disable tabs conversions.

Extra settings

Appearance settings window

This section allow to customize extra advanced settings:

  • Interactive preview: if the global output option is set to html enable javascript inside the preview windows. Use only if you use some higlight plugins that embed js code inside the output.
  • Arguments: extra arguments for the highlight executable. Arguments that contains a white space must be protected inside queted.
  • Append arguments (only for custom UTI settings): allow to set extra arguments to be appended to the global arguments.
  • Pre processor (only for custom UTI settings): set a program or a shell script to preprocess the source file before the formatting. The program must output to stdout the data to be passed to highlight. You must pass the name of the source file using the $targetHL placeholder. With the preprocessor you can handle file format not directly supported by highlight.
  • Syntax (only for custom UTI settings): set which language must be used to recognize the source file. If not set will be used the file name extension to recognize the format.

Some file format have a preconfigured custom settings to handle the data (for example java compiled class file can be decompiled before render).

Preview

The preview panel show an example of the output with the current settings. You can show the single theme color items or test the output with some example source files. You can also browse for a custom file to test the preview.

Theme editor

The application has a gui theme editor accessible form menu View/Themes editor. With this interface you can create a custom theme to use with highlight.

Theme editor

Standard themes provided by highlight cannot be edited but can be duplicated and then customized.

Clicking on an element of the preview blinks the corresponding item in the editor and vice versa.

Customized themes are saved in ~/Library/Application Support/Syntax Highlight/Themes.

Note for download precompiled release

The precompiled app is not notarized or signed. When you download the precompiled app you must strip quarantine flag. You can launch the app with right click (or ctrl click) on the app icon anche choosing the open action. Also you can execute this command from the terminal:

$ xattr -r -d com.apple.quarantine "FULL PATH OF THE Syntax Highlight.app (you can drag the file to get the pull path)" 

This must resolve the error of damage application when launch the app.

Note for developers

After cloning remember to fetch submodules:

$ git submodule init 
$ git submodule update

Credits

This application has originated from the anthonygelibert/QLColorCode.

Github

link
Stars: 183

Dependencies

Used By

Total: 0

Releases

- 2020-05-29 15:58:11

- 2020-05-22 15:02:41

- 2020-05-22 06:11:36

- 2020-05-21 15:07:26

- 2020-02-13 09:25:36

- 2020-01-09 21:56:28

Added an option to limit the amount of data to format - 2019-12-23 19:48:30

- 2019-11-29 22:23:12

New features:

  • XPC service splitted into two services. One is used by the quicklook extension with only the code to read the current settings and format the preview. The second one has also the code to change the settings, inquiry the themes and all the requested features for the main application interface. I hope this change makes the quicklook extension more reactive and consume less resources.
  • Rewrite the settings engine.

Some optimizations and bugfix - 2019-11-26 15:41:41

New features:

  • Support for .h header files.
  • Target to 10.15 (now the standard swift library is not embedded).
  • New interactive preview setting to allow the execution of js code inside the quicklook preview.

Bugfix:

  • Removed markdown support in the quicklook extension.
  • Fix little space for theme name on popover theme selector.
  • Images of help files have been compressed.
  • Added a margin aroud the preview on the quicklook window.
  • Fast generation of theme icons.

More supported formats - 2019-11-25 11:09:46

New features:

  • merge pull request https://github.com/sbarex/SourceCodeSyntaxHighlight/pull/18 (support for awk, bash, clojure, diff, haskell, lua, patch, rust, scala, text, zsh)
  • added support for .r file format.

Bugfix:

  • Correction of many typos.

New theme editor - 2019-11-25 10:24:43

New features:

  • Embedded highlight updated to 5.3.4.
  • Info panel about highlight (from App menu and from a info butto on preferences window).
  • Menu item inside app menu for open in the Finder the application support folder.
  • Redesign of preferences window for the theme selection.
  • GUI to view and edit the themes.
  • Inside the application support folder are saved the custom css styles and customized themes.

Bugfix:

  • Now double click on the quicklook preview open the file.
  • Bugfix on font preferences.
  • System for purging and migrating old settings to new system.

- 2019-11-17 19:41:01

- 2019-11-15 23:14:53

Short application and extension name - 2019-11-12 16:21:35

Short Application name.

Now the app works with space inside him path. Debug option to create on your desktop a colorize.log file to the log of last operations.

New preferences interface and customization for single file format - 2019-11-11 13:15:22

- 2019-10-29 12:07:07

- 2019-10-28 16:20:44

Embedded highlight - 2019-10-27 20:02:36