├── test ├── mdlocate.bogus_extension ├── test-encoding.py ├── test$var$escaping.py ├── objc │ ├── DMWindowMemoryController.m │ └── X11BridgeController.m ├── css │ ├── main-stylesheet.css │ └── blog-stylesheet.css └── test%%.plist ├── .gitmodules ├── .travis.yml ├── hl └── lua.hpp ├── src ├── Common.h ├── GeneratePreviewForURL.m ├── GenerateThumbnailForURL.m ├── Common.m ├── colorize.sh └── main.c ├── QLColorCode.xcodeproj ├── xcshareddata │ └── xcschemes │ │ ├── Package.xcscheme │ │ └── Travis.xcscheme └── project.pbxproj ├── .gitignore ├── Info.plist ├── README.md ├── CHANGELOG.md └── COPYING /test/mdlocate.bogus_extension: -------------------------------------------------------------------------------- 1 | #!/bin/sh -f 2 | 3 | mdfind "kMDItemFSName == \"$1\"" 4 | -------------------------------------------------------------------------------- /test/test-encoding.py: -------------------------------------------------------------------------------- 1 | # This file is encoded UTF-8 2 | 3 | print u"Hello würld" 4 | print u"This is a Lambda: λ" 5 | print u"Some Cyrillic for you: Позвоните пожалуйста в милицию!" 6 | -------------------------------------------------------------------------------- /test/test$var$escaping.py: -------------------------------------------------------------------------------- 1 | # This file is encoded UTF-8 2 | 3 | print u"Hello würld" 4 | print u"This is a Lambda: λ" 5 | print u"Some Cyrillic for you: Позвоните пожалуйста в милицию!" 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "hl/highlight"] 2 | path = hl/highlight 3 | url = https://gitlab.com/saalen/highlight.git 4 | [submodule "hl/lua"] 5 | path = hl/lua 6 | url = https://github.com/lua/lua.git 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | addons: 2 | homebrew: 3 | packages: 4 | - boost 5 | language: objective-c 6 | script: set -o pipefail && xcodebuild -project QLColorCode.xcodeproj -scheme Travis build | xcpretty 7 | -------------------------------------------------------------------------------- /hl/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /src/Common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Common.h 3 | * QLColorCode 4 | * 5 | * Created by Nathaniel Gray on 12/6/07. 6 | * Copyright 2007 Nathaniel Gray. 7 | * 8 | */ 9 | @import CoreFoundation; 10 | @import Foundation; 11 | 12 | #ifdef DEBUG 13 | #define n8log(...) NSLog(__VA_ARGS__) 14 | #else 15 | #define n8log(...) 16 | #endif 17 | 18 | #define myDomain @"org.n8gray.QLColorCode" 19 | 20 | // Status is 0 on success, nonzero on error (like a shell command) 21 | // If thumbnail is 1, only render enough of the file for a thumbnail 22 | NSData *colorizeURL(CFBundleRef myBundle, CFURLRef url, int *status, 23 | int thumbnail); 24 | -------------------------------------------------------------------------------- /src/GeneratePreviewForURL.m: -------------------------------------------------------------------------------- 1 | @import Cocoa; 2 | @import CoreFoundation; 3 | @import QuickLook; 4 | 5 | #import "Common.h" 6 | 7 | OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options); 8 | void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview); 9 | 10 | /* ----------------------------------------------------------------------------- 11 | Generate a preview for file 12 | 13 | This function's job is to create preview for designated file 14 | ----------------------------------------------------------------------------- */ 15 | 16 | OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options) 17 | { 18 | CFBundleRef bundle = QLPreviewRequestGetGeneratorBundle(preview); 19 | int status; 20 | 21 | CFDataRef data = (__bridge CFDataRef) colorizeURL(bundle, url, &status, 0); 22 | 23 | if (data) { 24 | CFDictionaryRef props = (__bridge CFDictionaryRef) [NSDictionary dictionary]; 25 | QLPreviewRequestSetDataRepresentation(preview, data, kUTTypeHTML, props); 26 | } 27 | 28 | return noErr; 29 | } 30 | 31 | void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview) 32 | { 33 | // Implement only if supported 34 | } 35 | -------------------------------------------------------------------------------- /src/GenerateThumbnailForURL.m: -------------------------------------------------------------------------------- 1 | @import Cocoa; 2 | @import CoreFoundation; 3 | @import QuickLook; 4 | 5 | #import "Common.h" 6 | 7 | OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize); 8 | void CancelThumbnailGeneration(void *thisInterface, QLThumbnailRequestRef thumbnail); 9 | 10 | /* ----------------------------------------------------------------------------- 11 | Generate a thumbnail for file 12 | 13 | This function's job is to create thumbnail for designated file as fast as possible 14 | ----------------------------------------------------------------------------- */ 15 | 16 | OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize) 17 | { 18 | @autoreleasepool { 19 | NSStringEncoding usedEncoding = 0; 20 | NSError *readError = nil; 21 | 22 | [NSString stringWithContentsOfURL:(__bridge NSURL*)url usedEncoding:&usedEncoding error:&readError]; 23 | 24 | if (usedEncoding == 0) { 25 | NSLog(@"Failed to determine encoding for file %@", [(__bridge NSURL*)url path]); 26 | return noErr; 27 | } 28 | 29 | if (QLThumbnailRequestIsCancelled(thumbnail)) 30 | return noErr; 31 | 32 | NSDictionary *previewProperties = @{ 33 | (NSString *)kQLPreviewPropertyStringEncodingKey : @( usedEncoding ) 34 | }; 35 | 36 | NSDictionary *properties = @{ 37 | (__bridge NSString *)kQLPreviewPropertyMIMETypeKey : @"text/html" 38 | }; 39 | 40 | QLThumbnailRequestSetThumbnailWithURLRepresentation( 41 | thumbnail, 42 | url, 43 | kUTTypePlainText, 44 | (__bridge CFDictionaryRef)previewProperties, 45 | (__bridge CFDictionaryRef)properties); 46 | 47 | return noErr; 48 | } 49 | } 50 | 51 | void CancelThumbnailGeneration(void *thisInterface, QLThumbnailRequestRef thumbnail) 52 | { 53 | // Implement only if supported 54 | } 55 | -------------------------------------------------------------------------------- /QLColorCode.xcodeproj/xcshareddata/xcschemes/Package.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 44 | 50 | 51 | 57 | 58 | 59 | 60 | 62 | 63 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /QLColorCode.xcodeproj/xcshareddata/xcschemes/Travis.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 44 | 50 | 51 | 52 | 53 | 59 | 60 | 62 | 63 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /test/objc/DMWindowMemoryController.m: -------------------------------------------------------------------------------- 1 | // 2 | // DMWindowMemoryController.m 3 | // DMWindowMemory 4 | // 5 | // Created by Nathaniel Gray on 5/25/06. 6 | // Copyright 2006 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "DMWindowMemoryController.h" 10 | #import "Notifications.h" 11 | 12 | @implementation DMWindowMemoryController 13 | 14 | - someMethod { 15 | } 16 | 17 | - someOtherMethod 18 | {} 19 | 20 | - foo : (baz) bar { 21 | } 22 | 23 | + blah { 24 | } 25 | 26 | - (NSString*) name { 27 | return @"Window Memory Plugin"; 28 | } 29 | - (NSString*) description { 30 | return @"A plugin to save and restore the positions of your windows when your screen configuration changes"; 31 | } 32 | - (int) interfaceVersion { 33 | return 1; 34 | } 35 | - (NSBundle*) preferencesBundle { 36 | return nil; 37 | } 38 | 39 | /* This is in response to notification that the screen geometry has changed */ 40 | - (void) handleScreenChange: (NSNotification *)notif { 41 | NSLog(@"*** handleScreenChange\n"); 42 | [mConfigurationLock lock]; 43 | NSEnumerator *configEnum = [mConfigurations objectEnumerator]; 44 | ScreenConfiguration *config; 45 | BOOL found = NO; 46 | while (config = [configEnum nextObject]) { 47 | if ([config matchesCurrentConfig]) { 48 | NSLog(@"Found matching config: %@", config); 49 | mCurrentConfig = config; 50 | [config restoreWindowLayout]; 51 | found = YES; 52 | break; 53 | } 54 | } 55 | if (!found) { 56 | config = [ScreenConfiguration configWithCurrent]; 57 | [mConfigurations insertObject:config 58 | atIndex:0]; 59 | mCurrentConfig = config; 60 | NSLog(@"Added new config: %@", config); 61 | } 62 | [mConfigurationLock unlock]; 63 | } 64 | 65 | /* This is in response to the periodic updates to the window layout on screen */ 66 | - (void) handleWindowChanges: (NSNotification *)notif { 67 | //NSLog(@"handleWindowChanges\n"); 68 | [mConfigurationLock lock]; 69 | [mCurrentConfig updateWindowLayout]; 70 | [mConfigurationLock unlock]; 71 | } 72 | 73 | - (void) pluginLoaded: (DMController*) controller withBundle: (NSBundle*) thisBundle 74 | { 75 | NSLog(@"DMWindowMemoryController pluginLoaded\n"); 76 | mController = controller; 77 | NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; 78 | mConfigurationLock = [[NSLock alloc] init]; 79 | [mConfigurationLock lock]; 80 | 81 | // Find out when screens are added/removed 82 | [nc addObserver: self 83 | selector: @selector(handleScreenChange:) 84 | name: NSApplicationDidChangeScreenParametersNotification 85 | object: nil]; 86 | 87 | // Get the periodic window layout updates 88 | [nc addObserver: self 89 | selector: @selector(handleWindowChanges:) 90 | name: NOTIFICATION_WINDOWLAYOUTUPDATED 91 | object: nil]; 92 | 93 | mCurrentConfig = [ScreenConfiguration configWithCurrent]; 94 | mConfigurations = [[NSMutableArray arrayWithObject:mCurrentConfig] retain]; 95 | [mConfigurationLock unlock]; 96 | NSLog(@"Finished initializing plugin\n"); 97 | } 98 | 99 | - (void) dealloc { 100 | [mConfigurationLock lock]; 101 | NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; 102 | [nc removeObserver:self]; 103 | // We don't release mCurrentConfig because we never actually retain it. 104 | if (mConfigurations) { 105 | [mConfigurations release]; 106 | mConfigurations = nil; 107 | } 108 | if (mController) { 109 | [mController release]; 110 | mController = nil; 111 | } 112 | [mConfigurationLock unlock]; 113 | [mConfigurationLock release]; 114 | [super dealloc]; 115 | } 116 | @end 117 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos 4 | 5 | ### macOS ### 6 | # General 7 | .DS_Store 8 | .AppleDouble 9 | .LSOverride 10 | 11 | # Icon must end with two \r 12 | Icon 13 | 14 | # Thumbnails 15 | ._* 16 | 17 | # Files that might appear in the root of a volume 18 | .DocumentRevisions-V100 19 | .fseventsd 20 | .Spotlight-V100 21 | .TemporaryItems 22 | .Trashes 23 | .VolumeIcon.icns 24 | .com.apple.timemachine.donotpresent 25 | 26 | # Directories potentially created on remote AFP share 27 | .AppleDB 28 | .AppleDesktop 29 | Network Trash Folder 30 | Temporary Items 31 | .apdisk 32 | 33 | # End of https://www.toptal.com/developers/gitignore/api/macos 34 | 35 | # Created by https://www.toptal.com/developers/gitignore/api/xcode 36 | # Edit at https://www.toptal.com/developers/gitignore?templates=xcode 37 | 38 | ### Xcode ### 39 | # Xcode 40 | # 41 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 42 | 43 | ## User settings 44 | xcuserdata/ 45 | 46 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 47 | *.xcscmblueprint 48 | *.xccheckout 49 | 50 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 51 | build/ 52 | DerivedData/ 53 | *.moved-aside 54 | *.pbxuser 55 | !default.pbxuser 56 | *.mode1v3 57 | !default.mode1v3 58 | *.mode2v3 59 | !default.mode2v3 60 | *.perspectivev3 61 | !default.perspectivev3 62 | 63 | ## Gcc Patch 64 | /*.gcno 65 | 66 | ### Xcode Patch ### 67 | *.xcodeproj/* 68 | !*.xcodeproj/project.pbxproj 69 | !*.xcodeproj/xcshareddata/ 70 | !*.xcworkspace/contents.xcworkspacedata 71 | **/xcshareddata/WorkspaceSettings.xcsettings 72 | 73 | # End of https://www.toptal.com/developers/gitignore/api/xcode 74 | 75 | # Created by https://www.toptal.com/developers/gitignore/api/objective-c 76 | # Edit at https://www.toptal.com/developers/gitignore?templates=objective-c 77 | 78 | ### Objective-C ### 79 | # Xcode 80 | # 81 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 82 | 83 | ## User settings 84 | xcuserdata/ 85 | 86 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 87 | *.xcscmblueprint 88 | *.xccheckout 89 | 90 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 91 | build/ 92 | DerivedData/ 93 | *.moved-aside 94 | *.pbxuser 95 | !default.pbxuser 96 | *.mode1v3 97 | !default.mode1v3 98 | *.mode2v3 99 | !default.mode2v3 100 | *.perspectivev3 101 | !default.perspectivev3 102 | 103 | ## Obj-C/Swift specific 104 | *.hmap 105 | 106 | ## App packaging 107 | *.ipa 108 | *.dSYM.zip 109 | *.dSYM 110 | 111 | # CocoaPods 112 | # We recommend against adding the Pods directory to your .gitignore. However 113 | # you should judge for yourself, the pros and cons are mentioned at: 114 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 115 | # Pods/ 116 | # Add this line if you want to avoid checking in source code from the Xcode workspace 117 | # *.xcworkspace 118 | 119 | # Carthage 120 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 121 | # Carthage/Checkouts 122 | 123 | Carthage/Build/ 124 | 125 | # fastlane 126 | # It is recommended to not store the screenshots in the git repo. 127 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 128 | # For more information about the recommended setup visit: 129 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 130 | 131 | fastlane/report.xml 132 | fastlane/Preview.html 133 | fastlane/screenshots/**/*.png 134 | fastlane/test_output 135 | 136 | # Code Injection 137 | # After new code Injection tools there's a generated folder /iOSInjectionProject 138 | # https://github.com/johnno1962/injectionforxcode 139 | 140 | iOSInjectionProject/ 141 | 142 | ### Objective-C Patch ### 143 | 144 | # End of https://www.toptal.com/developers/gitignore/api/objective-c 145 | 146 | release/ 147 | -------------------------------------------------------------------------------- /src/Common.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Common.c 3 | * QLColorCode 4 | * 5 | * Created by Nathaniel Gray on 12/6/07. 6 | * Copyright 2007 Nathaniel Gray. 7 | * 8 | * Modified by Anthony Gelibert on 9/5/12. 9 | * Copyright 2012 Anthony Gelibert. 10 | */ 11 | 12 | @import CoreFoundation; 13 | @import Foundation; 14 | 15 | #import // PATH_MAX 16 | 17 | #include "Common.h" 18 | 19 | 20 | NSData *runTask(NSString *script, NSDictionary *env, int *exitCode) { 21 | NSTask *task = [[NSTask alloc] init]; 22 | [task setCurrentDirectoryPath:@"/tmp"]; /* XXX: Fix this */ 23 | [task setEnvironment:env]; 24 | [task setLaunchPath:@"/bin/sh"]; 25 | [task setArguments:[NSArray arrayWithObjects:@"-c", script, nil]]; 26 | 27 | NSPipe *pipe; 28 | pipe = [NSPipe pipe]; 29 | [task setStandardOutput: pipe]; 30 | // Let stderr go to the usual place 31 | //[task setStandardError: pipe]; 32 | 33 | NSFileHandle *file; 34 | file = [pipe fileHandleForReading]; 35 | 36 | [task launch]; 37 | 38 | NSData *data; 39 | data = [file readDataToEndOfFile]; 40 | [task waitUntilExit]; 41 | 42 | *exitCode = [task terminationStatus]; 43 | [task release]; 44 | /* The docs claim this isn't needed, but we leak descriptors otherwise */ 45 | [file closeFile]; 46 | /*[pipe release];*/ 47 | 48 | return data; 49 | } 50 | 51 | NSString *pathOfURL(CFURLRef url) 52 | { 53 | NSString *targetCFS = [[(NSURL *)url absoluteURL] path]; 54 | n8log(@"targetCFS = %@", targetCFS); 55 | //return [targetCFS stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 56 | return targetCFS; 57 | } 58 | 59 | 60 | NSData *colorizeURL(CFBundleRef bundle, CFURLRef url, int *status, int thumbnail) 61 | { 62 | NSData *output = NULL; 63 | CFURLRef rsrcDirURL = CFBundleCopyResourcesDirectoryURL(bundle); 64 | NSString *rsrcEsc = pathOfURL(rsrcDirURL); 65 | CFRelease(rsrcDirURL); 66 | n8log(@"url = %@", url); 67 | NSString *targetEsc = pathOfURL(url); 68 | n8log(@"targetEsc = %@", targetEsc); 69 | 70 | // Set up preferences 71 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 72 | 73 | NSMutableDictionary *env = [NSMutableDictionary dictionaryWithDictionary: 74 | [[NSProcessInfo processInfo] environment]]; 75 | 76 | [env addEntriesFromDictionary:[NSDictionary dictionaryWithObjectsAndKeys: 77 | #ifdef DEBUG 78 | @"1", @"qlcc_debug", 79 | #endif 80 | @"10", @"fontSizePoints", 81 | @"Menlo", @"font", 82 | @"darkplus", @"darkTheme", 83 | @"edit-xcode", @"lightTheme", 84 | @"edit-xcode", @"hlTheme", 85 | // @"-lz -j 3 -t 4 --kw-case=capitalize ", @"extraHLFlags", 86 | @"-t 4 ", @"extraHLFlags", 87 | [rsrcEsc stringByAppendingString:@"/highlight"], @"pathHL", 88 | @"", @"maxFileSize", 89 | @"UTF-8", @"textEncoding", 90 | @"UTF-8", @"webkitTextEncoding", nil]]; 91 | 92 | 93 | [env addEntriesFromDictionary:[defaults persistentDomainForName:myDomain]]; 94 | 95 | // Change hlTheme according to system's darkmode setting. 96 | NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"]; 97 | if ([osxMode isEqual: @"Dark"]) { 98 | [env setObject:[env objectForKey:@"darkTheme"] forKey:@"hlTheme"]; 99 | } else { 100 | [env setObject:[env objectForKey:@"lightTheme"] forKey:@"hlTheme"]; 101 | } 102 | 103 | NSString *cmd = [NSString stringWithFormat: 104 | @"'%@/colorize.sh' '%@' '%@' %s", 105 | rsrcEsc, rsrcEsc, [targetEsc stringByReplacingOccurrencesOfString:@"'" withString:@"'\\''"], thumbnail ? "1" : "0"]; 106 | n8log(@"cmd = %@", cmd); 107 | 108 | output = runTask(cmd, env, status); 109 | if (*status != 0) { 110 | NSLog(@"QLColorCode: colorize.sh failed with exit code %d. Command was (%@).", 111 | *status, cmd); 112 | } 113 | return output; 114 | } 115 | -------------------------------------------------------------------------------- /src/colorize.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zsh -f 2 | 3 | ############################################################################### 4 | # This code is licensed under the GPL v3. See LICENSE.txt for details. 5 | # 6 | # Copyright 2007 Nathaniel Gray. 7 | # Copyright 2012-2018 Anthony Gelibert. 8 | # 9 | # Expects $1 = path to resources dir of bundle 10 | # $2 = name of file to colorize 11 | # $3 = 1 if you want enough for a thumbnail, 0 for the full file 12 | # 13 | # Produces HTML on stdout with exit code 0 on success 14 | ############################################################################### 15 | 16 | # Fail immediately on failure of sub-command 17 | setopt err_exit 18 | 19 | # Set the read-only variables 20 | rsrcDir="$1" 21 | target="$2" 22 | thumb="$3" 23 | cmd="$pathHL" 24 | 25 | function debug() { 26 | if [ "x$qlcc_debug" != "x" ]; then 27 | if [ "x$thumb" = "x0" ]; then 28 | echo "QLColorCode: $@" 1>&2 29 | fi; 30 | fi 31 | } 32 | 33 | debug "Starting colorize.sh by setting reader" 34 | reader=(cat ${target}) 35 | 36 | debug "Handling special cases" 37 | case ${target} in 38 | *.graffle | *.ps ) 39 | exit 1 40 | ;; 41 | *.iml ) 42 | lang=xml 43 | ;; 44 | *.d ) 45 | lang=make 46 | ;; 47 | *.fxml ) 48 | lang=fx 49 | ;; 50 | *.s | *.s79 ) 51 | lang=assembler 52 | ;; 53 | *.sb ) 54 | lang=lisp 55 | ;; 56 | *.java ) 57 | lang=java 58 | plugin=(--plug-in java_library) 59 | ;; 60 | *.pde | *.ino ) 61 | lang=c 62 | ;; 63 | *.c | *.cpp | *.ino ) 64 | lang=${target##*.} 65 | plugin=(--plug-in cpp_syslog --plug-in cpp_ref_cplusplus_com --plug-in cpp_ref_local_includes) 66 | ;; 67 | *.rdf | *.xul | *.ecore ) 68 | lang=xml 69 | ;; 70 | *.pyc ) 71 | lang=python 72 | reader=(/usr/local/bin/uncompyle6 ${target}) 73 | ;; 74 | *.ascr | *.scpt ) 75 | lang=applescript 76 | reader=(/usr/bin/osadecompile ${target}) 77 | ;; 78 | *.plist ) 79 | lang=xml 80 | reader=(/usr/bin/plutil -convert xml1 -o - ${target}) 81 | ;; 82 | *.sql ) 83 | if grep -q -E "SQLite .* database" <(file -b ${target}); then 84 | exit 1 85 | fi 86 | lang=sql 87 | ;; 88 | *.m ) 89 | lang=objc 90 | ;; 91 | *.am | *.in ) 92 | lang=make 93 | ;; 94 | *.mod ) 95 | lang=go 96 | ;; 97 | *.pch | *.h ) 98 | if grep -q "@interface" <(${target}) &> /dev/null; then 99 | lang=objc 100 | else 101 | lang=h 102 | fi 103 | ;; 104 | *.pl ) 105 | lang=pl 106 | plugin=(--plug-in perl_ref_perl_org) 107 | ;; 108 | *.py ) 109 | lang=py 110 | plugin=(--plug-in python_ref_python_org) 111 | ;; 112 | *.sh | *.zsh | *.bash | *.csh | *.bashrc | *.zshrc | *.xsh | *.bats ) 113 | lang=sh 114 | plugin=(--plug-in bash_functions) 115 | ;; 116 | *.scala ) 117 | lang=scala 118 | plugin=(--plug-in scala_ref_scala_lang_org) 119 | ;; 120 | *.cfg | *.properties | *.conf ) 121 | lang=ini 122 | ;; 123 | *.kmt ) 124 | lang=scala 125 | ;; 126 | *.adoc ) 127 | lang=asciidoc 128 | ;; 129 | * ) 130 | lang=${target##*.} 131 | ;; 132 | esac 133 | 134 | debug "Resolved ${target} to language $lang" 135 | 136 | go4it () { 137 | cmdOpts=(--plug-in reduce_filesize ${plugin} --plug-in outhtml_codefold --syntax=${lang} --quiet --include-style --font=${font} --font-size=${fontSizePoints} --style=${hlTheme} --encoding=${textEncoding} ${=extraHLFlags} --validate-input) 138 | 139 | debug "Generating the preview" 140 | if [ "${thumb}" = "1" ]; then 141 | ${reader} | head -n 100 | head -c 20000 | ${cmd} -D "${rsrcDir}" ${cmdOpts} && exit 0 142 | elif [ -n "${maxFileSize}" ]; then 143 | ${reader} | head -c ${maxFileSize} | ${cmd} -D "${rsrcDir}" -T "${target}" ${cmdOpts} && exit 0 144 | else 145 | ${reader} | ${cmd} -D "${rsrcDir}" -T "${target}" ${cmdOpts} && exit 0 146 | fi 147 | } 148 | 149 | setopt no_err_exit 150 | 151 | go4it 152 | # Uh-oh, it didn't work. Fall back to rendering the file as plain 153 | debug "First try failed, second try..." 154 | lang=txt 155 | go4it 156 | 157 | debug "Reached the end of the file. That should not happen." 158 | exit 101 159 | -------------------------------------------------------------------------------- /test/css/main-stylesheet.css: -------------------------------------------------------------------------------- 1 | /* For help understanding this stuff see: 2 | http://www.w3.org/TR/2004/CR-CSS21-20040225/cover.html#minitoc 3 | 4 | #f30 reddish (bird) 5 | #f60 orange (bedspread) 6 | #f93 light orange (bird beak) 7 | 8 | #630 brown (wood streaks) 9 | #c60 light brown (wood) 10 | #cc0 yellowish (egg yolk) 11 | 12 | #036 dark blue (streaks on wall) 13 | #369 light blue (picture frame) 14 | 15 | #666 gray (wall) 16 | #ccc light gray (shaded white) 17 | 18 | #996 Yellowish olive green. 19 | #50573f Classic n8gray NEdit green. 20 | 21 | */ 22 | 23 | /* Generic styles */ 24 | body { 25 | background: black; 26 | } 27 | a { 28 | color: inherit 29 | } 30 | 31 | a:link:hover, a:visited:hover { 32 | color: #f30 33 | } 34 | 35 | /* Style for gradient row at top */ 36 | .gradrow img { 37 | display: block; 38 | } 39 | 40 | /* This is a trick for getting something to center vertically. 41 | see: http://www.wpdfd.com/editorial/thebox/deadcentre4.html */ 42 | #horizon { 43 | /* A 1px-high, full-width box halfway down the screen */ 44 | position: absolute; 45 | top: 50%; 46 | left: 0px; 47 | width: 100%; 48 | height: 1px; 49 | overflow: visible; /* This is critical! */ 50 | display: block; 51 | } 52 | 53 | #topdiv { 54 | /* The "absolute" positioning of the nested table is relative to #horizon */ 55 | position: absolute; 56 | bottom: -175px; /* Half the height */ 57 | left: 50%; /* Put the left edge in the center, except... */ 58 | margin-left: -150px; /* Move the left edge back so image is centered */ 59 | 60 | background-image: url("/images/redlizard_duncan_parks-tail.png"); 61 | background-repeat: no-repeat; 62 | background-position: bottom left; 63 | 64 | padding-bottom: 70px; /* Ensure the bottom of the tail is visible */ 65 | } 66 | 67 | #lizardpanel { 68 | background: #50573f; 69 | /* background: #996; */ 70 | /* background: white; */ 71 | border: solid #996; 72 | border-left-width: 3px; 73 | border-bottom-width: 3px; 74 | border-right-width: 0; 75 | border-top-width: 0; 76 | width: 121px; 77 | overflow: visible; 78 | } 79 | 80 | #notail { 81 | position: absolute; 82 | bottom: 0px; 83 | z-index: 9999; 84 | } 85 | 86 | /* #tail { 87 | position: absolute; 88 | bottom: -30px; 89 | z-index: 1; 90 | } */ 91 | 92 | .rtpanel { 93 | background-repeat: no-repeat; 94 | background-position: left; 95 | } 96 | .navtable { 97 | z-index: 5000; 98 | } 99 | 100 | .navtitle_l, 101 | .navtitle_r { 102 | color: #f93; 103 | background: #50573f; 104 | font-weight: bold; 105 | font-family: Arial,Helvetica,Sans-Serif; 106 | text-shadow: rgba(0, 0, 0, 0.4) 3px 3px 3px; /* h, v, blurriness */ 107 | padding: 2px; 108 | padding-left: 4px; 109 | padding-right: 4px; 110 | text-align: center; 111 | border: 3px solid #996; 112 | border-bottom-width: 0; 113 | } 114 | .navtitle_r { 115 | border-left-width: 0; 116 | } 117 | .navtitle_l { 118 | border-right-width: 0; 119 | } 120 | 121 | 122 | .navcell { 123 | padding: 4px; 124 | background: #996; 125 | color: white; 126 | text-align: center; 127 | } 128 | 129 | /* Style the button list differently on the front page */ 130 | .navcell #buttonList a { 131 | background-image: url(/images/blankBoth.gif); 132 | 133 | } 134 | 135 | /* The table inside the gradient, containing the button bar and content. */ 136 | .innerTable { 137 | background-color: #996; 138 | } 139 | 140 | /* The left column (with the button bar) */ 141 | .leftcol { 142 | padding: 18px; 143 | } 144 | 145 | /* The right column (with the content) */ 146 | .rightcol { 147 | background-color: #50573f; 148 | padding: 18px; 149 | padding-top: 15px; 150 | border: 3px solid #996; 151 | border-left-width: 0; 152 | 153 | color: white; 154 | } 155 | .rightcol h3 { 156 | color: #f93; 157 | } 158 | .rightcol a { 159 | color: yellow; 160 | } 161 | 162 | /* ************************************************************************* */ 163 | /* This is the magic CSS rollover code! */ 164 | /* ************************************************************************* */ 165 | 166 | #buttonList { 167 | /* This style makes a list look nothing like a list. :-) */ 168 | list-style-type: none; 169 | border: 0; 170 | padding: 0; 171 | margin: 0; 172 | } 173 | 174 | #buttonList > li { /* The > selects immediate children */ 175 | /* Pad between the buttons */ 176 | padding-bottom: 2px; 177 | } 178 | 179 | #buttonList a { 180 | /* Make the entire button clickable by turning links into blocks */ 181 | display: block; 182 | height: 36px; 183 | width: 150px; 184 | line-height: 36px; /* This causes the text to be vertically centered */ 185 | font-family: Arial Narrow,Helvetica,Sans-serif,Verdana,Geneva; 186 | font-size: 14pt; 187 | font-weight: bold; 188 | text-align: center; 189 | text-decoration: none; /* Disable underline */ 190 | background-image: url(/images/blankBoth.gif); 191 | background-repeat: no-repeat; 192 | } 193 | 194 | #buttonList a:hover, 195 | #buttonList a#here { 196 | /* Highlight on hover, or by default for current page's button */ 197 | color: yellow; 198 | background-position: top left; 199 | } 200 | 201 | #buttonList a, 202 | #buttonList a:active, 203 | #buttonList a#here:active { 204 | /* Unhighlight unselected buttons, and while clicking */ 205 | color: #220; 206 | background-position: bottom left; 207 | } 208 | -------------------------------------------------------------------------------- /Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeName 11 | 12 | CFBundleTypeRole 13 | QLGenerator 14 | LSItemContentTypes 15 | 16 | dyn.ah62d4rv4ge81q4pr 17 | public.source-code 18 | public.ruby-script 19 | public.yaml 20 | public.php-script 21 | com.netscape.javascript-source 22 | com.microsoft.c-sharp 23 | com.microsoft.f-sharp 24 | public.css 25 | com.apple.applescript.script 26 | public.xml 27 | com.apple.property-list 28 | org.tug.tex 29 | com.sun.java-class 30 | com.sun.java-source 31 | org.vim.vim-script 32 | org.tug.lua 33 | public.tex 34 | public.text 35 | public.shell-script 36 | public.c-header 37 | public.objective-c-source 38 | public.c-source 39 | public.c-plus-plus-source 40 | public.c-plus-plus-header 41 | public.objective-c-plus-plus-source 42 | public.assembly-source 43 | com.apple.rez-source 44 | public.mig-source 45 | public.swift-source 46 | public.pascal-source 47 | com.apple.symbol-export 48 | public.csh-script 49 | public.zsh-script 50 | com.apple.terminal.shell-script 51 | com.apple.terminal.session 52 | com.apple.terminal.settings 53 | public.python-script 54 | com.apple.xcode.strings-text 55 | dyn.ah62d4rv4ge81g6pq 56 | dyn.ah62d4rv4ge8007a 57 | dyn.ah62d4rv4ge80s6xbqv0gn 58 | dyn.ah62d4rv4ge81g25brvuu 59 | dyn.ah62d4rv4ge80g62 60 | dyn.ah62d4rv4ge80w5pq 61 | dyn.ah62d4rv4ge80s52 62 | dyn.ah62d4rv4ge80g2pcqf0a 63 | dyn.ah62d4rv4ge81e62 64 | dyn.ah62d4rv4ge80u62 65 | dyn.ah62d4rv4ge80g6u 66 | dyn.ah62d4rv4ge80g3xh 67 | dyn.ah62d4rv4ge81q7pf 68 | dyn.ah62d4rv4ge81a6xtsbw1e7dmqz3u 69 | dyn.ah62d4rv4ge80e2p4qz0a 70 | dyn.ah62d4rv4ge80e8xq 71 | dyn.ah62d4rv4ge81u65e 72 | dyn.ah62d4rv4ge81u6pzqz3hw 73 | org.vim.xsl-file 74 | dyn.ah62d4rv4ge81u7k 75 | dyn.ah62d4rv4ge81u6pr 76 | dyn.ah62d4rv4ge81u6k 77 | dyn.ah62d4rv4ge8007dx 78 | dyn.ah62d4rv4ge80e2py 79 | dyn.ah62d4rv4ge80q4pxra 80 | dyn.ah62d4rv4ge81u65k 81 | dyn.ah62d4rv4ge81a8pd 82 | dyn.ah62d4rv4ge81e65y 83 | dyn.ah62d4rv4ge80n5a 84 | dyn.ah62d4rv4ge80w5u 85 | dyn.ah62d4rv4ge81k 86 | dyn.ah62d4rv4ge80c5k 87 | dyn.ah62d4rv4ge80c3dtqq 88 | public.perl-script 89 | dyn.ah62d4rv4ge80e2pysq 90 | public.patch-file 91 | public.bash-script 92 | com.apple.xcode.bash-script 93 | com.apple.xcode.csh-script 94 | com.apple.xcode.ksh-script 95 | com.apple.xcode.tcsh-script 96 | com.apple.xcode.yacc-source 97 | com.apple.xcode.zsh-script 98 | dyn.ah62d4rv4ge81a63v 99 | dyn.ah62d4rv4ge81k3x0qf3hg 100 | dyn.ah62d4rv4ge81k3u 101 | dyn.ah62d4rv4ge81u65q 102 | dyn.ah62d4rv4ge80w5xm 103 | dyn.ah62d4rv4ge8023pxsq 104 | dyn.ah62d4rv4ge80g55sq2 105 | 106 | 107 | 108 | CFBundleExecutable 109 | ${EXECUTABLE_NAME} 110 | CFBundleIconFile 111 | 112 | CFBundleIdentifier 113 | $(PRODUCT_BUNDLE_IDENTIFIER) 114 | CFBundleInfoDictionaryVersion 115 | 6.0 116 | CFBundleName 117 | ${PRODUCT_NAME} 118 | CFBundleShortVersionString 119 | $(MARKETING_VERSION) 120 | CFBundleVersion 121 | $(CURRENT_PROJECT_VERSION) 122 | CFPlugInDynamicRegisterFunction 123 | 124 | CFPlugInDynamicRegistration 125 | NO 126 | CFPlugInFactories 127 | 128 | C044543D-70A1-46D8-A908-4B8AEA1197A4 129 | QuickLookGeneratorPluginFactory 130 | 131 | CFPlugInTypes 132 | 133 | 5E2D9680-5022-40FA-B806-43349622E5B9 134 | 135 | C044543D-70A1-46D8-A908-4B8AEA1197A4 136 | 137 | 138 | CFPlugInUnloadFunction 139 | 140 | QLNeedsToBeRunInMainThread 141 | 142 | QLPreviewHeight 143 | 800 144 | QLPreviewWidth 145 | 800 146 | QLSupportsConcurrentRequests 147 | 148 | QLThumbnailMinimumSize 149 | 17 150 | 151 | 152 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QLColorCode 2 | 3 | [![Build Status](https://travis-ci.org/anthonygelibert/QLColorCode.svg?branch=master)](https://travis-ci.org/anthonygelibert/QLColorCode) 4 | 5 | **Original project:** 6 | 7 | This is a Quick Look plug-in that renders source code with syntax highlighting, using the 8 | [Highlight library](http://www.andre-simon.de). 9 | 10 | To install the plug-in, just drag it to `~/Library/QuickLook`. You may need to create that folder if it doesn't already 11 | exist. 12 | 13 | Alternatively, if you use [Homebrew Cask](https://github.com/caskroom/homebrew-cask), install with 14 | `brew install --cask qlcolorcode`. Also available on [MacPorts](https://www.macports.org): `port install QLColorCode`. 15 | 16 | **To build the project, you must have Boost headers on your system in `/opt/local/include` or `/usr/local/include`.** 17 | 18 | ## Settings 19 | 20 | If you want to configure `QLColorCode`, there are several `defaults` commands that could be useful: 21 | 22 | Setting the text encoding (default is `UTF-8`). Two settings are required. The first sets Highlight's encoding, the 23 | second sets Webkit's: 24 | 25 | defaults write org.n8gray.QLColorCode textEncoding UTF-16 26 | defaults write org.n8gray.QLColorCode webkitTextEncoding UTF-16 27 | 28 | Setting the font (default is `Menlo`): 29 | 30 | defaults write org.n8gray.QLColorCode font Monaco 31 | 32 | Setting the font size (default is `10`): 33 | 34 | defaults write org.n8gray.QLColorCode fontSizePoints 9 35 | 36 | Setting the color style for `light` and `dark` mode (see 37 | [all available themes](http://www.andre-simon.de/doku/highlight/theme-samples.php)): 38 | 39 | defaults write org.n8gray.QLColorCode lightTheme solarized-light 40 | defaults write org.n8gray.QLColorCode darkTheme solarized-dark 41 | 42 | Setting the thumbnail color style (deactivated by default): 43 | 44 | defaults write org.n8gray.QLColorCode hlThumbTheme ide-xcode 45 | 46 | Setting the maximum size (in bytes, deactivated by default) for previewed files: 47 | 48 | defaults write org.n8gray.QLColorCode maxFileSize 1000000 49 | 50 | zSetting any extra command-line flags for Highlight (see below): 51 | 52 | defaults write org.n8gray.QLColorCode extraHLFlags '-l -W' 53 | 54 | Here are some useful 'highlight' command-line flags (from the man page): 55 | 56 | -F, --reformat=