Looking for syntax highlighted QuickLook code previews? Look no further

I’d like to introduce you to the latest member of the PreviewApp family: PreviewCode, which provides syntax-coloured QuickLook previews and Finder icon thumbnails for over 50 programming languages, including Swift, Objective-C, C++, Rust, JavaScript and Python, and data file types for macOS. You can choose to preview your source code any of 100 dark and light themes.

Previewed code courtesy of PreviewCode

Available now from the Mac App Store for a very modest consideration, PreviewCode delivers its previews and thumbnails through a pair of app extensions, but the main is app is where you apply your preferences:

  • Select the monospace font in which your code will be presented.
  • Choose the code’s text size.
  • Pick a preview theme.

PreviewCode lets you choose from any monospace font installed on your Mac, in a range of sizes from 10pt to 28pt.

Pick a theme, any theme…

PreviewCode’s themes are listed alphabetically, and you can choose to view them all, or just the dark or light ones. Preview settings are applied as soon as you click on the Preferences pane’s Save button, so you check out your choices immediately — and go straight back and make a different selection if your current choices are not to your satisfaction.

Did I mention there are lots of themes?

All of the themes and the code that applies them are provided by Highlight.js, a popular JavaScript framework designed to colourise source code presented by websites. Seeking a suitable Swift wrapper for Hightlight.js, I discovered Highlightr, but quickly found it to be based on an old version of the library that the Highlight.js team recommends is no longer used.

Highlightr appears to be no longer actively maintained — it hasn’t been updated since 2018 — and I needed to make some changes as well as bring it up to date with supported Highlight.js code. So the work on PreviewCode resulted in a second project: HighlighterSwift, a new wrapper for Hightlight.js offered as a Swift Package. The code derives from Highlightr, but is now fully commented, uses Highlight.js 10, and includes a number of fixes and improvements. Like Highlighr, it’s available under the terms of the MIT licence for easy inclusion in other projects.

Just a selection of the many languages and data files PreviewCode supports

Here’s the list of languages and files supported by PreviewCode:

  • ActionScript (.as)
  • Ada (.ads, .adb)
  • AppleScript (.applescript)
  • Arduino (.ino)
  • Basic (.bas)
  • Brainfuck (.b, .bf)
  • C (.c, .h)
  • C++ (.cpp, .hpp)
  • C# (.csx)
  • Clojure (.clj, .cljs, .cljc, .edn)
  • CoffeeScript (.coffee)
  • Dart (.dart)
  • Dylan (.dylan, .lid)
  • Elixir (.ex, .exs)
  • Erlang (.erl, .hrl)
  • Fortran (.for)
  • F# (.fs, .fsx, .fsi, .fsscript)
  • Go (.go)
  • Haskell (.hs, .lhs)
  • Java (.java)
  • JavaScript (.js)
  • Julia (.jl)
  • Kotlin (.kt, .kts, .ktm)
  • Lisp (.lisp, .lsp, .l, .cl, .fasl)
  • Lua (.lua)
  • Objective-C (.m)
  • Pascal (.pas)
  • Perl (.perl)
  • PHP (.php)
  • Python (.py)
  • Ruby (.rb)
  • Rust (.rs)
  • Swift (.swift)
  • TypeScript (.tsx)
  • Visual Basic Script (.vbs)
  • Bash (.sh)
  • C Shell (.csh)
  • Korn Shell (.ksh)
  • TCSH (.tsch)
  • Z Shell (.zsh)
  • ARM Assembler (.s)
  • x86-64 Assembler (.asm, .nasm)
  • CSS (.css)
  • LaTex (.tex)
  • Protobuf (.proto)
  • SASS/SCSS (.scss, .sass)
  • SQL script (.sql)
  • Twig (.twig)

Incidentally, my other PreviewApps, PreviewMarkdown and PreviewYaml, have both been recently updated too: patch updates that improve their stability and add some under-the-hood enhancements derived from the work on PreviewCode. You can get them all from the Mac App Store:

The source is available on GitHub.

Stay ahead of git with this sharp script

I work on quite a few git repositories at once, and I don’t always commit changes in one before making changes to another. Or if I do, I don’t always push the changes up straight away. That might not be best practice in software development, but hey, it’s what I do. The issue for me is remembering what state each repo is in. Here’s the script I use to tell me.

Continue reading

Crop picture files with confidence and pixel-precise offsets, using sips and imageprep

I recently had a rather large number of screenshots to process: specifically to crop them down to a small area about a third of screen width in and two-thirds of its height down. I could have done this manually, but it’s easy enough to make mis-crops when you’re cropping a couple of images by eye, let alone a 100 or so. The solution? Get your Mac to do it for you. Here’s how.

imageprep 6.30
Continue reading

How to fix ‘xcodebuild’ macOS Terminal slowdowns

For a while, running commands and scripts in macOS’ Terminal has felt slower than it should, especially when opening Terminal for the first time. Clearly my .zshrc file was being run, but there was a very noticeable pause between the completion of the script and before the prompt appeared. The gap was much less on my M1 Mac than my Intel machine, but still noticeable. Got the same problem? Here’s how to fix it.

macOS Terminal
Continue reading

Looking for YAML macOS QuickLook file previews? With PreviewYaml 1.0.0, you got ’em!

Last week I announced the release of a new version of PreviewMarkdown that will preview YAML front matter in Markdown files. Work on that release prompted me to code a new app that enables QuickLook previews and Finder icon thumbnails of YAML files.

QuickLook previews and icon thumbnails of YAML files can now be yours
Continue reading

Now available: PreviewMarkdown 1.3.0 with YAML support

Version 1.3.0 of PreviewMarkdown has just been released. Its key new feature: you now have the option to view YAML front matter in Markdown file previews. This is really handy if, like me, you use a static site generator and use YAML to record content metadata at the top of your Markdown page files.

With PreviewMarkdown 1.3.0, you can now preview files’ YAML content too
Continue reading

Take advantage of Xcode’s hidden diagnostics to debug multi-threaded application code

PreviewMarkdown’s Thumbnailer component, an App Extension which generates Finder icon thumbnail previews of Markdown documents, recently started showing some odd behaviour. Tracking down the cause provided some interesting insights into writing macOS software for a multi-threaded environment.

Thumbnailer-rendered thumbnails
Continue reading